⽤VB.NET做excel插件开发,可能需要为excel添加⾃定义的⼯具栏。这个也是⾮常的简单的。
以下是引⽤⽚段:
  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 _DisconnectMode, ByRef custom As System.Array)
  Implements Extensibility.IDTExtensibility2.OnDisconnection
  End Subvb所有代码
  Public Sub OnConnection()Sub OnConnection(ByVal application As Object, ByVal connectMode _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),

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。