楼主 nothingwmm |
Q: 定制个性化 2003版菜单? A: 以下代码获得常用的命令栏后,还可以进一步根据附件附带的命令的ID,随意增加常用的个性化命令,具体的ID,具体添加方法见代码的后面那些行,含义和ID 参考附件里的文件。 效果图如
代码参考如下。具体可见附件。
- Private Sub ShowOldStyleMenus()
- On Error Resume Next
- Dim cBar As CommandBar
- Dim cBarCtrl As CommandBarControl
- Dim sMenuName As String
- Dim s**Name As String
- Dim iMenu As Integer
- sMenuName = "Old Style Menu"
- s**Name = "Old Style**"
- CommandBars(sMenuName).Delete '如果之前有菜单栏,删除之
- Set cBar = CommandBars.Add(sMenuName, , , True) '添加命令栏,名字为sMenuName,是一个临时菜单栏,即常用菜单项
- '参考:Set newMbar = CommandBars.Add _
- (Name:="newMenubar", Position:=msoBarRight, _
- MenuBar:=True, temporary:=True)
- With cBar
- .Visible = True '临时菜单栏可见
- For iMenu = 1 To 10
- Set cBarCtrl = .Controls.Add(Type:=msoControlPopup, ID:=30001 + iMenu) '依次添加2003版的弹出是菜单
- Next iMenu
- Set cBarCtrl = .Controls.Add(Type:=msoControlPopup, ID:=30022) '图表菜单
- Set cBarCtrl = .Controls.Add(Type:=msoControlPopup, ID:=30177) '自选图形
- End With
- CommandBars(s**Name).Delete '删除临时菜单栏
- Set cBar = CommandBars.Add(s**Name, , , True) '设置变量
- With cBar
- .Visible = True
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=2520) 'New
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=23) 'Open
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=3) 'Save
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=4) 'Print
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=109) 'Print Preview
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=2) 'Spelling
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=21) 'Cut
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=19) 'Copy
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=22) 'Paste
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=108) 'Format Painter
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=210) 'Sort Ascending
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=211) 'Sort Descending
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=984) 'Help
- Set cBarCtrl = .Controls.Add(Type:=msoControlComboBox, ID:=1728) 'Font
- Set cBarCtrl = .Controls.Add(Type:=msoControlComboBox, ID:=1731) 'Font Size
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=113) 'Bold
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=114) 'Italic
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=115) 'Underline
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=120) 'Align Left
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=122) 'Center
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=121) 'Align Right
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=402) 'Merge and Center
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=395) 'Accounting Number Format
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=396) 'Percent Style
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=397) 'Comma Style
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=398) 'Increase Decimal
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=399) 'Decrease Decimal
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=3162) 'Decrease Indent
- Set cBarCtrl = .Controls.Add(Type:=msoControlButton, ID:=3161) 'Increase Indent
- End With '依次设置常用的命令
- Set cBar = Nothing '清楚变量
- Set cBarCtrl = Nothing
- On Error GoTo 0
- End Sub
所有系统菜单命令ID及图标.rar 2003版个性化菜单定制.rar |