深入探索VBA:自定义菜单、工具栏与工作表函数
1. VBA快捷菜单操作
VBA可用于操作Excel的右键快捷菜单,下面是一些实用示例。
- 重置所有内置右键菜单 :以下代码可将所有内置工具栏恢复到初始状态。
Sub ResetAll()
Dim cbar As CommandBar
For Each cbar In Application.CommandBars
If cbar.Type = msoBarTypePopup Then
cbar.Reset
cbar.Enabled = True
End If
Next cbar
End Sub
此过程仅在有人执行过添加、删除项目或禁用快捷菜单的VBA代码时才会生效。
- 向单元格快捷菜单添加新项 :以“Change Case”实用工具为例,可通过以下代码将其添加到单元格快捷菜单。
Sub AddToShortCut()
Dim Bar As CommandBar
Dim NewControl As CommandBarButton
DeleteFromShortcut
Set Bar = Application.CommandBars("Cell")
Set NewControl = Bar.Controls.Add _
(Typ
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



