自己顶一下,无人跟贴,我还是把代码贴出来,这样比较直观,方便大家予以指点,谢谢。
------------------------------------------------------------------------------------------------
标准模块(Module1:)
Public xlapp As Excel.Application
Public MenuEvents As ToolsMenuEvents
类模块(ToolsMenuEvents)
Private WithEvents btnMenuItem1 As
Private WithEvents btnMenuItem2 As
Private WithEvents btnMenuItem As
Sub CreateMenuItems()
With (1).Controls.Add(Type:=msoControlPopup, Temporary:=True)
.Caption = "MyToolBar"
Set btnMenuItem1 = .Controls.Add
With btnMenuItem1
.Caption = "计算"
.BeginGroup = True
.FaceId = 23
End With
Set btnMenuItem2 = .Controls.Add
With btnMenuItem2
.Caption = "统计"
.BeginGroup = False
.FaceId = 24
End With
End With
End Sub
Sub DeleteMenuItems()
On Error Resume Next
(1).Controls("MyToolBar").Delete
End Sub
Private Sub btnMenuItem1_Click(ByVal Ctrl As , CancelDefault As Boolean)
MsgBox "计算"
End Sub
Private Sub btnMenuItem2_Click(ByVal Ctrl As , CancelDefault As Boolean)
MsgBox "统计"
End Sub
设计器(Connect)
Option Explicit
Implements IDTExtensibility2
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set xlapp = Application
Set MenuEvents = New ToolsMenuEvents
MenuEvents.CreateMenuItems
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
MenuEvents.DeleteMenuItems
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub