VBA 获取Excel内置菜单、对话框的ID和工具栏名称
2010-08-25 09:44:32| 分类: Excel自动化 | 标签: |字号大中小 订阅
一、获取菜单名称及ID
Private Sub CommandButton1_Click()Dim cp As CommandBarPopupDim cb1 As CommandBarButtonSet cp = CommandBars("Worksheet Menu Bar").Controls("文件(&F)")For Each cb1 In cp.Controls MsgBox CStr(cb1.ID) + cb1.CaptionNext cb1End Sub
二、对话框的ID
Sub test()For Each bar In Application.CommandBars debug.print bar.NameNextEnd Sub
常用的屏蔽代码:
Application.CommandBars(""Worksheet Menu Bar"").Enabled = False ""屏蔽菜单栏
Application.DisplayFormulaBar = False ""屏蔽编辑栏
Application.DisplayStatusBar = False ""屏蔽状态栏
下面任选一组即可,不可同时出现。
Application.CommandBars(""Standard"").Visible = False ""屏蔽常用工具栏,右键可选
Application.CommandBars(""Formatting"").Visible = False ""屏蔽格式工具栏,右键可选
Application.CommandBars(""Standard"").Enabled = False ""去除常用工具栏,右键也删掉
Application.CommandBars(""Formatting"").Enabled = False ""去除格式工具栏,右键也删掉
Application.CommandBars(""Toolbar list"").Enabled = False ""屏蔽右键工具栏
Application.CommandBars(""cell"").Enabled = False ""屏蔽单元格右键单击
Application.CommandBars(""Column"").Enabled = False ""屏蔽列右键单击
Application.CommandBars(""Row"").Enabled = False ""屏蔽行右键单击
Application.Assistant.Visible = False ""应用程序的辅助的可见
Application.CommandBars.DisableCustomize = True ""去除右键工具栏中的“自定义”
ActiveWindow.DisplayHeadings = False ""屏蔽行号列标
ActiveWindow.DisplayWorkbookTabs = False ""屏蔽工作表标签
ActiveWindow.DisplayVerticalScrollBar = False ""屏蔽垂直滚动条
ActiveWindow.DisplayHorizontalScrollBar = False ""屏蔽水平滚动条
Application.CommandBars(""ply"").Enabled = False ""屏蔽工作表标签右键单击
Application.CommandBars(""Visual basic"").Enabled = False ""屏蔽应用程序的<命令块>(""Visual basic"" )的激活
Application.OnKey ""%{f11}"", "" "" ""屏蔽组合键ALT+F11,%代表ALT
Application.OnKey ""%{F11}"" ""解除屏蔽ALT+F11
Application.OnKey ""%{f8}"", "" "" ""屏蔽组合键ALT+F8
Application.OnKey ""%{f8}"" ""解除屏蔽ALT+F8
Application.OnKey ""^{f11}"", ""VBEdit"" ""屏蔽组合键Ctrl+F11,插入宏表,^代表Ctrl
Application.OnKey ""^{f11}"" ""恢复组合键Ctrl+F11,插入宏表
Application.OnKey ""^f"", "" "" ""屏蔽组合键Ctrl+F,查找
Application.OnKey ""^h"", "" "" ""屏蔽组合键Ctrl+H,替换
Application.OnKey ""^{Break}"", "" "" ""屏蔽CTRL+Break中断
Application.OnKey ""^{Break}"" ""解除CTRL+Break中断
崋说 简单传播