扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
以下是引用片段: Public Class ConnectClass Connect Implements Extensibility.IDTExtensibility2 Dim app As Excel.Application Dim wb As Excel.Workbook Dim ws As Excel.Worksheet Dim addInInstance As Object Dim pasteText As Microsoft.Office.Core.CommandBarButton ‘定义一个工具栏按钮 Public Sub OnBeginShutdown()Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown End Sub Public Sub OnAddInsUpdate()Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate End Sub Public Sub OnStartupComplete()Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete End Sub Public Sub OnDisconnection()Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection End Sub Public Sub OnConnection()Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection If TypeOf (application) Is Excel.Application Then app = CType(application, Excel.Application) addInInstance = addInInst wb = app.ActiveWorkbook ws = CType(wb.ActiveSheet, Excel.Worksheet) Dim toolbar As Microsoft.Office.Core.CommandBar = Nothing If Not app Is Nothing Then toolbar = AddToolbar(app, "专用工具栏") ’添加工具栏 End If ’ 建立按钮添加文本 pasteText = MakeANewButton(toolbar, "Insert text", 1044, AddressOf pasteText_Click) ’添加工具栏按钮并帮定事件 End Sub ’添加工具栏 Private Function AddToolbar()Function AddToolbar(ByVal ex As Excel.Application, _ ByVal toolbarName As String) As Microsoft.Office.Core.CommandBar Dim toolBar As Microsoft.Office.Core.CommandBar = Nothing Try ’ 为add-in建立一个命令条 toolBar = CType(ex.CommandBars.Add(toolbarName, Microsoft.Office.Core.MsoBarPosition.msoBarTop, , True), Microsoft.Office.Core.CommandBar) toolBar.Visible = True Return toolBar Catch Return Nothing End Try End Function ’在工具栏上添加一个按钮 Private Function MakeANewButton()Function MakeANewButton(ByVal commandBar As Microsoft.Office.Core.CommandBar, ByVal caption As String, ByVal faceID As Integer, ByVal clickHandler As Microsoft.Office. Core._CommandBarButtonEvents_ClickEventHandler) As Microsoft.Office.Core.CommandBarButton Try Dim newButton As Microsoft.Office.Core.CommandBarButton newButton = CType(commandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton), Microsoft.Office.Core.CommandBarButton) newButton.Caption = caption newButton.FaceId = faceID AddHandler newButton.Click, clickHandler Return newButton Catch ex As System.Exception Return Nothing End Try End Function ’点击工具条按钮时应该执行的程序 Public Sub pasteText_Click()Sub pasteText_Click(ByVal barButton As Microsoft.Office.Core.CommandBarButton, ByRef someBool As Boolean) Dim text As String = "" Dim data As System.Windows.Forms.IDataObject = System.Windows.Forms.Clipboard.GetDataObject() If data.GetDataPresent(System.Windows.Forms.DataFormats.Text) Then text = data.GetData(System.Windows.Forms.DataFormats.Text).ToString() If (Not app Is Nothing) Then Me.app.ActiveCell.Value = text End If End If End Sub End Class |
这样程序就完成了,赶紧动手体验吧!
婵犵鈧啿鈧綊鎮樻径鎰畺闁靛ň鏅滄慨婊堟偨椤栨稓鎽冮柟鐑╂櫊瀹曟岸宕堕埡鍌滄殸闂佽鍨伴崢鏍姳閿涘嫭鍠嗘い銈呭姬婵☆偅婢樺Λ妤呮偂濞嗘挸瀚夐柍褜鍓熷顒侊紣娓氣偓閻涙捇鏌涘┑鍛樂缂佹鐭傞獮搴ㄥ焵椤掑嫬瀚夋い鏍ㄧ懁缁诲棝鏌熼褍鐏茬紒杈ㄧ箞閺屽洭鏁愰崟顓犳澖闁荤姳闄嶉崹钘壩i崟顖涘殜闁硅泛顫曢埀顒€锕︾槐鏃堝箣閻愬弬妤呮煛閸偄鐏﹂柛瀣墬缁傛帞鎹勯搹瑙勵啈闂佸搫瀚烽崹閬嶅磻瀹ュ鍎嶉柛鏇ㄥ墯娴犳ê霉閿濆棗鈻曢柍褜鍓氶弻銊ф閻愬鈻曢悗锝傛櫇椤忛亶鏌曢崱顓熷
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者