|
- Dim oXL As Object
- Dim mnMain As Office.CommandBarPopup
- Dim mnMain2 As Office.CommandBarPopup
- Dim WithEvents mn1 As Office.CommandBarButton
- Dim WithEvents mn2 As Office.CommandBarButton
- Dim WithEvents MyButton As Office.CommandBarButton
- Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
- ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
- ByVal AddInInst As Object, custom() As Variant)
- On Error Resume Next
- Set oXL = Application
- oXL.CommandBars("Worksheet Menu Bar").Controls("期末处理(K)").Delete
- Set mnMain = oXL.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=msoControlPopup, Before:=11)
- mnMain.Caption = "期末处理(K)"
- Set mn1 = mnMain.Controls.Add(Type:=msoControlButton, Before:=1)
- With mn1
- .Caption = "移动1"
- .OnAction = "!<" & AddInInst.ProgId & ">"
- .FaceId = 162
- '.Visible = True
- End With
- Set mnMain2 = mnMain.Controls.Add(Type:=msoControlPopup, Before:=2)
- With mnMain2
- .Caption = "移动2"
- .BeginGroup = True '增加间隔符
- '.OnAction = "!<" & AddInInst.ProgId & ">"
- '.FaceId = 300
- '.Visible = True
- Set mn1 = .Controls.Add(Type:=msoControlButton)
- With mn1
- .Caption = "子菜单1"
- .Visible = True
- End With
- Set mn2 = .Controls.Add(Type:=msoControlButton)
- With mn2
- .Caption = "子菜单2"
- .Visible = True
- End With
- End With
- End Sub
- Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
- AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
- On Error Resume Next
- MsgBox "My Addin was disconnected by " & _
- IIf(RemoveMode = ext_dm_HostShutdown, _
- "Excel shutdown.", "end user.")
- mn2.Delete
- mn1.Delete
- mnMain.Delete
- Set mn2 = Nothing
- Set mn1 = Nothing
- Set mnMain = Nothing
- Set oXL = Nothing
- End Sub
- Private Sub mn1_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
- MsgBox "Hello!"
- End Sub
- Private Sub mn2_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
- MsgBox "Hi!"
- End Sub
复制代码 |
|