VBA操作与自定义函数全解析
1. VBA快捷菜单操作
在Excel中,我们可以使用VBA来操作右键快捷菜单,以下是几种常见的操作示例。
1.1 重置所有内置右键菜单
以下代码可将所有内置工具栏重置为原始状态:
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代码时才会生效。
1.2 向单元格快捷菜单添加新项
下面的代码可向单元格快捷菜单添加一个新的菜单项“Change Case”:
Sub AddToShortCut()
Dim Bar As CommandBar
Dim NewControl As CommandBarButton
DeleteFromShortcut
Set Bar = Application.CommandBars("Cell")
Set NewControl = Bar.Controls.Add _
(Type:=mso
超级会员免费看
订阅专栏 解锁全文
60

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



