我想知道如何使用VBA代码向右键菜单添加新图标,这将是粘贴特殊值 Excel功能的快捷方式(可以在Excel 2010中找到,但不能在2007年找到) 。添加图标本身不是问题所在,但是是否有可以与该图标关联的通用方法(不是VBA宏)?
下面添加与ToggleCaseMacro
宏相关联的图标的代码(此处未定义):
Sub AddToCellMenu()
Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl
' Delete the controls first to avoid duplicates.
Call DeleteFromCellMenu
' Set ContextMenu to the Cell context menu.
Set ContextMenu = Application.CommandBars("Cell")
' Add one built-in button(Save = 3) to the Cell context menu.
ContextMenu.Controls.Add Type:=msoControlButton, ID:=3, before:=1
' Add one custom button to the Cell context menu.
With ContextMenu.Controls.Add(Type:=msoControlButton, before:=2)
.OnAction = "'" & ThisWorkbook.Name & "'!" & "ToggleCaseMacro"
.FaceId = 59
.Caption = "Toggle Case Upper/Lower/Proper"
.Tag = "My_Cell_Control_Tag"
End With
End Sub
答案 0 :(得分:1)
你只需要添加:
ContextMenu.Controls.Add Type:=msoControlButton, ID:=370, Before:=2