【发布时间】:2014-06-05 09:43:32
【问题描述】:
我想知道如何使用 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
【问题讨论】:
标签: vba excel excel-formula excel-2007