要在xla启动的时候添加菜单栏的方法
在thisbook中添加这么一段
Private Sub Workbook_Open()
Call menu
End Sub
menu函数
函数中建立了一条新的工具栏,随后在上面添加了一个下拉栏(msoControlPopup)
下拉之后显示addToolBar,addMenu,AddrightMenu,rightMenuReset,uninstall
━━━━━━━━━━━━━━━━━━━━━━━━━━
Sub menu()
On Error Resume Next
Application.CommandBars("myMnu").Delete
Set myMnu = Application.CommandBars.Add
With myMnu
.Visible = True
.Position = msoBarTop
.Name = "myMnu"
End With
Set subMenu = myMnu.Controls.Add(Type:=msoControlPopup)
subMenu.Caption = "menu1"
Set KJ = subMenu.Controls.Add(Type:=msoControlButton)
With KJ
.Caption = "addToolBar"
.OnAction = "addToolBar"
End With
Set KJ = subMenu.Controls.Add(Type:=msoControlButton)
With KJ
.Caption = "addMenu"
.OnAction = "addMenu"
End With
Set KJ = subMenu.Controls.Add(Type:=msoControlButton)
With KJ
.Caption = "AddrightMenu"
.OnAction = "AddrightMenu"
End With
Set KJ = subMenu.Controls.Add(Type:=msoControlButton)
With KJ
.Caption = "rightMenuReset"
.OnAction = "rightMenuReset"
End With
Set KJ = subMenu.Controls.Add(Type:=msoControlButton)
With KJ
.Caption = "uninstall"
.OnAction = "uninstall"
End With
End Sub
━━━━━━━━━━━━━━━━━━━━━━━━━━
在工具栏【标准】中添加一个感叹号的按钮
faceid : 459是一个感叹号
Caption:是鼠标放上去之后显示的内容
━━━━━━━━━━━━━━━━━━━━━━━━━━
Sub addToolBar()
For Each ct In CommandBars("standard").Controls
If ct.Caption = "myMenu:My Setting Menu" Then
Exit Sub
End If
Next
Set newitem = CommandBars("standard").Controls.Add(Type:=msoControlButton, ID:=1, Before:=19)
With newitem
.Style = msoButtonIcon
.Caption = "myMenu:My Setting Menu"
.OnAction = "showAbout"
.FaceId = 459
End With
End Sub