【问题标题】:Excel VBA Adding 'paste special as value' icon to right click menu (cell context menu customization)Excel VBA 在右键菜单中添加“粘贴特殊值”图标(单元格上下文菜单自定义)
【发布时间】: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

MSDN page with above code

【问题讨论】:

标签: vba excel excel-formula excel-2007


【解决方案1】:

你只需要添加:

ContextMenu.Controls.Add Type:=msoControlButton, ID:=370, Before:=2

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 2013-07-30
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多