Sub Create_Menu()
Const Menu_Name As String = "My New Main_Menu"
Dim Before_number As Integer
Dim X As Integer
On Error Resume Next
CommandBars("Menu Bar").Controls(Menu_Name).Delete '删除最后菜单
Before_number = CommandBars("Menu Bar").Controls.Count + 1
Err.Clear
X = 1 '删除历史自定义菜单
Do Until Err.Number <> 0
CommandBars("Custom Popup " & X).Delete
X = X + 1
Loop
Err.Clear
CommandBars("Menu Bar").Controls.Add Type:=msoControlPopup, Before:=Before_number
CommandBars("Menu Bar").Controls(Before_number).Caption = Menu_Name
For X = 1 To 10 '这里可以加入数据库的访问代码
CommandBars("Custom Popup 1").Controls.Add Type:=msoControlButton, Before:=X
CommandBars("Custom Popup 1").Controls(X).Caption = "吸海垂虹" & X
CommandBars("Custom Popup 1").Controls(X).OnAction = "NewMacros.Proc_Menu"
Next
End Sub
Sub Proc_Menu() '这里可以加入菜单的处理代码
MsgBox CommandBars.ActionControl.Caption
End Sub
本文地址:http://com.8s8s.com/it/it6565.htm