ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: xiaojun0301

[分享] Excel个性化菜单攻略大全!

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2013-9-4 22:10 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖已被收录到知识树中,索引项:UI界面定制
顶,好贴,期待附件,感谢楼主分享!

TA的精华主题

TA的得分主题

发表于 2013-9-5 22:39 | 显示全部楼层
非常好的学习资料,谢谢分享!

TA的精华主题

TA的得分主题

发表于 2013-9-6 10:46 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 banjinjiu 于 2013-9-6 10:48 编辑

我编辑了一部分,不全,并且删除一些,和楼主的意思不完全相同,供大家参考。
  1. Sub Id_Control() '返回活动菜单栏的 ID
  2. Dim myId As Object
  3. Set myId = CommandBars("Worksheet Menu Bar").Controls("Tools")
  4. MsgBox myId.Caption & Chr(13) & myId.ID
  5. End Sub
  6. Sub MenuBars_GetName() '返回活动菜单栏的名称
  7. MsgBox CommandBars.ActiveMenuBar.Name
  8. End Sub
  9. Public OriginalMenuBar As Object
  10. Sub MenuBars_Capture() '重置菜单栏
  11. Set OriginalMenuBar = CommandBars.ActiveMenuBar
  12. End Sub
  13. Sub MenuBar_Display() '从可用菜单栏列表中删除内置“图表”菜单栏
  14. CommandBars("Chart").Enabled = False
  15. End Sub
  16. Sub MenuBar_Display2() '从可用菜单栏中添加内置“图表”菜单栏
  17. CommandBars("Chart").Enabled = True
  18. End Sub
  19. Sub MenuBar_Restore() '还原内置“图表”菜单栏
  20. CommandBars("Chart").Reset
  21. End Sub
  22. Sub Menu_Restore() '还原“工作表”菜单栏上的内置“图表”菜单栏
  23. Dim myMnu As Object
  24. Set myMnu = CommandBars("Chart")
  25. myMnu.Reset
  26. End Sub
  27. Sub MenuBar_Create() '创建自定义命令栏
  28. Application.CommandBars.Add Name:="张妍"
  29. End Sub
  30. Sub MenuBar_Delete() '删除自定义命令栏
  31. CommandBars("张妍").Delete
  32. End Sub
  33. Sub Menu_Create() '栏添加自定义菜单控件
  34. Dim myMnu As Object
  35. Set myMnu = CommandBars("Worksheet menu bar").Controls.Add(Type:=msoControlPopup, before:=3)
  36. With myMnu
  37. .Caption = "New & Menu"
  38. End With
  39. End Sub
  40. Sub Menu_Disable() '禁用“New Menu”菜单
  41. CommandBars("Worksheet menu bar").Controls("New & Menu").Enabled = False
  42. End Sub
  43. Sub Menu_Disable2() '启用命令栏上的菜单控件
  44. CommandBars("Worksheet menu bar").Controls("New & Menu").Enabled = True
  45. End Sub
  46. Sub Menu_Delete() '删除命令栏上的菜单控件
  47. CommandBars("Worksheet menu bar").Controls("张妍").Delete
  48. End Sub
  49. Sub menuItem_AddSeparator() '在“插入”菜单上的工作表命令之前添加分隔
  50. CommandBars("Worksheet menu bar").Controls("Insert").Controls("Worksheet").BeginGroup = True
  51. End Sub
  52. Sub menuItem_AddSeparator2() '删除在“插入”菜单上的工作表命令之前添加分隔
  53. CommandBars("Worksheet menu bar").Controls("Insert").Controls("Worksheet").BeginGroup = False
  54. End Sub
  55. Sub menuItem_Create() '在“工作表”菜单栏的“工具”菜单上创建名为 Custom1 的新命令
  56. With CommandBars("Worksheet menu bar").Controls("Tools")
  57. .Controls.Add(Type:=msoControlButton, before:=1).Caption = "Custom1"
  58. .Controls("Custom1").OnAction = "Code_Custom1"
  59. End With
  60. End Sub
  61. Sub menuItem_checkMark() '在 Custom1 命令未选中的情况下在其旁边放置一个选中标记;如果 Custom1 命令已选中,则将删除该选中标记
  62. Dim myPopup As Object
  63. Set myPopup = CommandBars("Worksheet menu bar").Controls("Tools")
  64. If myPopup.Controls("Custom1").State = msoButtonDown Then
  65. ' Remove check mark next to menu item.
  66. myPopup.Controls("Custom1").State = msoButtonUp
  67. MsgBox "Custom1 is now unchecked"
  68. Else
  69. ' Add check mark next to menu item.
  70. myPopup.Controls("Custom1").State = msoButtonDown
  71. MsgBox "Custom1 is now checked"
  72. End If
  73. End Sub
  74. Sub MenuItem_Disable() '禁用在“工具”菜单上创建的 Custom1 命令
  75. Dim myCmd As Object
  76. Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")
  77. myCmd.Controls("Custom1").Enabled = False
  78. End Sub
  79. Sub MenuItem_Enable() '启用禁用的 Custom1 命令
  80. Dim myCmd As Object
  81. Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")
  82. myCmd.Controls("Custom1").Enabled = True
  83. End Sub
  84. Sub menuItem_Delete() '删除“文件”菜单上的“保存”命令
  85. Dim myCmd As Object
  86. Set myCmd = CommandBars("Worksheet menu bar").Controls("File")
  87. myCmd.Controls("Save").Delete
  88. End Sub
  89. Sub menuItem_Restore() '先删除“保存”命令,然后又将其还原
  90. Dim myCmd As Object
  91. Set myCmd = CommandBars("Worksheet menu bar").Controls("文件")
  92. ' Id 3 refers to the Save menu item control.
  93. myCmd.Controls.Add Type:=msoControlButton, ID:=3, before:=5
  94. End Sub
  95. Sub SubMenu_Create() '向“工作表”菜单栏上的“工具”菜单添加名为“NewSub”的新子菜单
  96. Dim newSub As Object
  97. Set newSub = CommandBars("Worksheet menu bar").Controls("Tools")
  98. With newSub
  99. .Controls.Add(Type:=msoControlPopup, before:=1).Caption = "NewSub"
  100. End With
  101. End Sub
  102. Sub SubMenu_AddItem() '向“NewSub”子菜单添加名为“SubItem1”的新命令,单击“SubItem1”时,它将运行 Code_SubItem1 宏
  103. Dim newSubItem As Object
  104. Set newSubItem = CommandBars("Worksheet menu bar") _
  105. .Controls("Tools").Controls("NewSub")
  106. With newSubItem
  107. .Controls.Add(Type:=msoControlButton, before:=1).Caption = "SubItem1"
  108. .Controls("SubItem1").OnAction = "Code_SubItem1"
  109. End With
  110. End Sub
  111. Sub SubMenu_DisableItem() '禁用创建的 SubItem 命令
  112. CommandBars("Worksheet menu bar").Controls("Tools") _
  113. .Controls("NewSub").Controls("SubItem1").Enabled = False
  114. End Sub
  115. Sub SubMenu_DisableItem2() '启用同一 SubItem 命令
  116. CommandBars("Worksheet menu bar").Controls("Tools") _
  117. .Controls("NewSub").Controls("SubItem1").Enabled = True
  118. End Sub
  119. Sub SubMenu_DeleteItem() '删除'在“NewSub”子菜单上创建的 SubItem1 命令
  120. CommandBars("Worksheet menu bar").Controls("Tools") _
  121. .Controls("NewSub").Controls("SubItem1").Delete
  122. End Sub
  123. Sub SubMenu_DisableSub() '禁用在“工具”菜单上创建的“NewSub”子菜单
  124. CommandBars("Worksheet menu bar").Controls("Tools").Controls("NewSub").Enabled = False
  125. End Sub
  126. Sub SubMenu_DisableSub3() '启用在“工具”菜单上创建的“NewSub”子菜单
  127. CommandBars("Worksheet menu bar").Controls("Tools").Controls("NewSub").Enabled = True
  128. End Sub
  129. Sub SubMenu_DeleteSub() '删除在“工具”菜单上创建的“NewSub”子菜单
  130. CommandBars("Worksheet menu bar").Controls("Tools").Controls("NewSub").Delete
  131. End Sub
  132. Sub Shortcut_Create() '创建右键快捷菜单栏
  133. Dim myShtCtBar As Object
  134. Set myShtCtBar = CommandBars.Add(Name:="myShortcutBar", Position:=msoBarPopup)
  135. 'This displays the shortcut menu bar.
  136. '200, 200 refers to the screen position in pixels as x and y coordinates.
  137. myShtCtBar.ShowPopup 200, 200
  138. End Sub
  139. Sub Shortcut_AddItem() '在“myShortcutBar”快捷菜单栏上创建名为 Item1 的新菜单命令。当您单击“Item1”时,它将运行 Code_Item1 宏
  140. Dim myBar As Object
  141. Set myBar = CommandBars("myShortcutBar")
  142. With myBar
  143. .Controls.Add(Type:=msoControlButton, before:=1).Caption = "Item1"
  144. .Controls("Item1").OnAction = "Code_Item1"
  145. End With
  146. myBar.ShowPopup 200, 200
  147. End Sub
  148. Sub Shortcut_DisableItem() '禁用创建的 Item1 命令
  149. Set myBar = CommandBars("myShortcutBar")
  150. myBar.Controls("Item1").Enabled = False
  151. myBar.ShowPopup 200, 200
  152. End Sub
  153. Sub Shortcut_DisableItem2() '启用创建的 Item1 命令
  154. Set myBar = CommandBars("myShortcutBar")
  155. myBar.Controls("Item1").Enabled = True
  156. myBar.ShowPopup 200, 200
  157. End Sub
  158. Sub Shortcut_DeleteItem() '删除“myShortcutBar”快捷菜单栏上的名为 Item1 的菜单命令
  159. Set myBar = CommandBars("myShortcutBar")
  160. myBar.Controls("Item1").Delete
  161. myBar.ShowPopup 200, 200
  162. End Sub
  163. Sub Shortcut_DeleteShortCutBar() '删除创建的“myShortCutBar”快捷菜单栏
  164. CommandBars("MyShortCutBar").Delete
  165. End Sub
  166. Sub Shortcut_RestoreItem() '还原工作表“单元格”快捷菜单栏上的默认命令
  167. CommandBars("Cell").Reset
  168. End Sub
  169. Sub ShortcutSub_Create() '在工作表“单元格”快捷菜单上添加名为“NewSub”的新子菜单
  170. CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1) _
  171. .Caption = "NewSub"
  172. ' This displays the shortcut menu bar.
  173. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  174. CommandBars("Cell").ShowPopup 200, 200
  175. End Sub
  176. Sub ShortcutSub_AddItem() '向创建的子菜单“NewSub”中添加 SubItem1 命令。然后,当您单击“SubItem1”时,它将运行 Code_SubItem1 宏
  177. Dim newSubItem As Object
  178. Set newSubItem = CommandBars("Cell").Controls("NewSub")
  179. With newSubItem
  180. .Controls.Add(Type:=msoControlButton, before:=1).Caption = "subItem1"
  181. ' This will run the subItem1_Code macro when subItem1 is clicked.
  182. .Controls("subItem1").OnAction = "Code_subItem1"
  183. End With
  184. ' This displays the Cell shortcut menu bar.
  185. ' 200, 200 refers to the screen position in pixels as x and y coordinates CommandBars("Cell").ShowPopup 200, 200
  186. End Sub
  187. Sub ShortcutSub_DisableItem() '禁用“NewSub”子菜单上的 SubItem1 命令
  188. CommandBars("Cell").Controls("NewSub").Controls("subItem1").Enabled = False
  189. ' This displays the Cell shortcut menu bar.
  190. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  191. CommandBars("Cell").ShowPopup 200, 200
  192. End Sub
  193. Sub ShortcutSub_DisableItem2() '启用“NewSub”子菜单上的 SubItem1 命令
  194. CommandBars("Cell").Controls("NewSub").Controls("subItem1").Enabled = True
  195. ' This displays the Cell shortcut menu bar.
  196. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  197. CommandBars("Cell").ShowPopup 200, 200
  198. End Sub
  199. Sub ShortcutSub_DeleteItem() '删除“NewSub”子菜单上的 SubItem1 命令
  200. CommandBars("Cell").Controls("NewSub").Controls("subItem1").Delete
  201. ' This displays the Cell shortcut menu bar.
  202. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  203. CommandBars("Cell").ShowPopup 200, 200
  204. End Sub
  205. Sub ShortcutSub_DisableSub() '禁用“单元格”快捷菜单栏上的“NewSub”子菜单
  206. CommandBars("Cell").Controls("NewSub").Enabled = False
  207. ' This displays the Cell shortcut menu bar.
  208. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  209. CommandBars("Cell").ShowPopup 200, 200
  210. End Sub
  211. Sub ShortcutSub_DisableSub2() '启用“单元格”快捷菜单栏上的“NewSub”子菜单
  212. CommandBars("Cell").Controls("NewSub").Enabled = True
  213. ' This displays the Cell shortcut menu bar.
  214. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  215. CommandBars("Cell").ShowPopup 200, 200
  216. End Sub
  217. Sub ShortcutSub_DeleteSub() '删除您在“单元格”快捷菜单栏上创建的“NewSub”子菜单
  218. CommandBars("Cell").Controls("NewSub").Delete
  219. ' This displays the Cell shortcut menu bar.
  220. ' 200, 200 refers to the screen position in pixels as x and y coordinates.
  221. CommandBars("Cell").ShowPopup 200, 200
  222. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2013-9-6 11:52 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-10-22 07:17 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

感谢分享!

TA的精华主题

TA的得分主题

发表于 2013-10-22 08:08 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-10-24 17:05 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2013-10-25 19:01 | 显示全部楼层
做个标记,总结得很好,谢谢分享

TA的精华主题

TA的得分主题

发表于 2015-6-23 21:27 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2015-12-19 11:53 | 显示全部楼层
子菜单实现超链接打开工作簿
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-12-22 18:50 , Processed in 0.045512 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表