Excel VBA添加“将特殊粘贴值”图标添加到右键菜单(单元格上下文菜单自定义)
我想知道如何使用VBA代码添加新的图标到右键菜单,这将成为Excel Excelfunction(可以在Excel 2010中find,但不是在2007年)中的特殊粘贴的快捷方式。 添加图标本身不是问题,但有通用的方法(而不是VBAmacros),可以与该图标关联?
下面添加与ToggleCaseMacro
macros相关的图标的代码(这里没有定义):
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
MSDN页面上面的代码
你只需要添加:
ContextMenu.Controls.Add Type:=msoControlButton, ID:=370, Before:=2