Excel VBA删除右键单击';粘贴选项';在单元格内编辑时的菜单组

Excel VBA删除右键单击';粘贴选项';在单元格内编辑时的菜单组,vba,excel,commandbar,Vba,Excel,Commandbar,我需要使用VBA从Excel 2010中的右键单击菜单中删除“粘贴选项” 我能够删除我不需要的所有不必要的“正常”控制项(如“Cu&t”、“复制”、“粘贴和特殊…”等),但无法删除“粘贴选项”及其图标子项。我还从Excel文件->选项->高级->剪切复制和粘贴中删除了“粘贴选项”,但这对右键单击“粘贴选项”没有影响。我已经到处寻找解决方案,但在网上任何地方都找不到这方面的参考资料 我还检查了VBA“Locals”窗口中的CommandBar对象,查看了所有属性,但看不到“粘贴选项”的位置 提前感

我需要使用VBA从Excel 2010中的右键单击菜单中删除“粘贴选项”

我能够删除我不需要的所有不必要的“正常”控制项(如“Cu&t”、“复制”、“粘贴和特殊…”等),但无法删除“粘贴选项”及其图标子项。我还从Excel文件->选项->高级->剪切复制和粘贴中删除了“粘贴选项”,但这对右键单击“粘贴选项”没有影响。我已经到处寻找解决方案,但在网上任何地方都找不到这方面的参考资料

我还检查了VBA“Locals”窗口中的CommandBar对象,查看了所有属性,但看不到“粘贴选项”的位置


提前感谢

使用customui编辑器,您可以将其添加到customui14部分

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
        <command idMso="Paste" enabled="false"/>
        <command idMso="PasteGallery" enabled="false"/>
        <command idMso="PasteGalleryMini" enabled="false"/>
        <command idMso="PasteMenu" enabled="false"/>
        <command idMso="PasteLink" enabled="false"/>
        <command idMso="PasteAsHyperlink" enabled="false"/>
        <command idMso="PasteSpecialDialog" enabled="false"/>
        <command idMso="PasteFormatting" enabled="false"/>
        <command idMso="PasteFormulas" enabled="false"/>
        <command idMso="PasteValues" enabled="false"/>
        <command idMso="PasteFormulasAndNumberFormatting" enabled="false"/>
        <command idMso="PasteTranspose" enabled="false"/>
        <command idMso="PastePictureLink" enabled="false"/>
    </commands>
</customUI>

如果要隐藏控件,则必须为要操作的每个菜单隐藏控件。例如,单元格菜单

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <contextMenus>
        <contextMenu idMso="ContextMenuCell">
            <gallery idMso="PasteGalleryMini" visible="false"/>
        </contextMenu>
    </contextMenus>
</customUI>

使用customui编辑器,您可以将其添加到customui14部件中

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
        <command idMso="Paste" enabled="false"/>
        <command idMso="PasteGallery" enabled="false"/>
        <command idMso="PasteGalleryMini" enabled="false"/>
        <command idMso="PasteMenu" enabled="false"/>
        <command idMso="PasteLink" enabled="false"/>
        <command idMso="PasteAsHyperlink" enabled="false"/>
        <command idMso="PasteSpecialDialog" enabled="false"/>
        <command idMso="PasteFormatting" enabled="false"/>
        <command idMso="PasteFormulas" enabled="false"/>
        <command idMso="PasteValues" enabled="false"/>
        <command idMso="PasteFormulasAndNumberFormatting" enabled="false"/>
        <command idMso="PasteTranspose" enabled="false"/>
        <command idMso="PastePictureLink" enabled="false"/>
    </commands>
</customUI>

如果要隐藏控件,则必须为要操作的每个菜单隐藏控件。例如,单元格菜单

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <contextMenus>
        <contextMenu idMso="ContextMenuCell">
            <gallery idMso="PasteGalleryMini" visible="false"/>
        </contextMenu>
    </contextMenus>
</customUI>

使用for循环,以下是我的上下文菜单的ID和标题:

ID Caption 21 Cu&t 19 &Copy 22 &Paste 21437 Paste &Special... 3624 &Paste Table 25536 Smart &Lookup 32713 Data T&ype 33409 Translate 295 Insert C&ells... 27690 Insert C&ells... 292 &Delete... 3125 Clear Co&ntents 24508 &Quick Analysis 31623 Sp&arklines 31402 Filt&er 31435 S&ort 2031 Insert Co&mment 1592 Delete Co&mment 1593 Sh&ow/Hide Comments 855 &Format Cells... 1966 Pic&k From Drop-down List... 1614 &Show Phonetic Field 13380 Define N&ame... 1576 &Hyperlink... 1577 Edit &Hyperlink... 1015 &Open Hyperlink 3626 &Remove Hyperlink 11299 E&xpand to detail 31595 Additional Act&ions 178 F&ull Screen 22577 &Additional Actions ID标题 21立方英尺 19&复印件 22&粘贴 21437粘贴和特殊。。。 3624&粘贴表 25536智能和查找 32713数据T&ype 33409翻译 295插入C&ells。。。 27690插入C&ells。。。 292&删除。。。 3125清晰内容 24508&快速分析 31623 Sp和arklines 31402过滤器和过滤器 31435 S&ort 2031插入Co&mment 1592删除Co&mment 1593 Sh&ow/隐藏注释 855&格式化单元格。。。 1966从下拉列表中选择Pic&k。。。 1614&显示语音字段 13380定义N&ame。。。 1576&超链接。。。 1577编辑和超链接。。。 1015&打开超链接 3626删除超链接(&R) 11299 E&xpand至详图 31595其他法案和条例 178 F&ull屏幕 22577和其他行动 所以,如果你去掉了“粘贴”和“特殊粘贴”,那么所有的粘贴选项都消失了。不太清楚“粘贴表”指的是什么

For Each menuItem In Application.CommandBars("Cell").Controls If menuItem.ID = 22 or menuItem.ID = 21437 Then menuItem.Delete Next 对于Application.CommandBars(“单元格”)控件中的每个菜单项 如果menuItem.ID=22或menuItem.ID=21437,则menuItem.Delete 下一个
使用for循环,以下是我的上下文菜单的ID和标题:

ID Caption 21 Cu&t 19 &Copy 22 &Paste 21437 Paste &Special... 3624 &Paste Table 25536 Smart &Lookup 32713 Data T&ype 33409 Translate 295 Insert C&ells... 27690 Insert C&ells... 292 &Delete... 3125 Clear Co&ntents 24508 &Quick Analysis 31623 Sp&arklines 31402 Filt&er 31435 S&ort 2031 Insert Co&mment 1592 Delete Co&mment 1593 Sh&ow/Hide Comments 855 &Format Cells... 1966 Pic&k From Drop-down List... 1614 &Show Phonetic Field 13380 Define N&ame... 1576 &Hyperlink... 1577 Edit &Hyperlink... 1015 &Open Hyperlink 3626 &Remove Hyperlink 11299 E&xpand to detail 31595 Additional Act&ions 178 F&ull Screen 22577 &Additional Actions ID标题 21立方英尺 19&复印件 22&粘贴 21437粘贴和特殊。。。 3624&粘贴表 25536智能和查找 32713数据T&ype 33409翻译 295插入C&ells。。。 27690插入C&ells。。。 292&删除。。。 3125清晰内容 24508&快速分析 31623 Sp和arklines 31402过滤器和过滤器 31435 S&ort 2031插入Co&mment 1592删除Co&mment 1593 Sh&ow/隐藏注释 855&格式化单元格。。。 1966从下拉列表中选择Pic&k。。。 1614&显示语音字段 13380定义N&ame。。。 1576&超链接。。。 1577编辑和超链接。。。 1015&打开超链接 3626删除超链接(&R) 11299 E&xpand至详图 31595其他法案和条例 178 F&ull屏幕 22577和其他行动 所以,如果你去掉了“粘贴”和“特殊粘贴”,那么所有的粘贴选项都消失了。不太清楚“粘贴表”指的是什么

For Each menuItem In Application.CommandBars("Cell").Controls If menuItem.ID = 22 or menuItem.ID = 21437 Then menuItem.Delete Next 对于Application.CommandBars(“单元格”)控件中的每个菜单项 如果menuItem.ID=22或menuItem.ID=21437,则menuItem.Delete 下一个
是否仅用于一个工作簿?是的,仅用于一个工作簿和其中唯一可见的工作表。是否仅用于一个工作簿?是的,仅用于一个工作簿和其中唯一可见的工作表。嗨,JosieP,非常感谢。我从下载了customUI编辑器,并按照说明添加了代码,“粘贴选项:”项现在被禁用。有什么方法可以隐藏它吗?@JosieP我可以成功隐藏粘贴选项,但我无法隐藏粘贴特殊。你好,JosieP,非常感谢。我从下载了customUI编辑器,并按照说明添加了代码,“粘贴选项:”项现在被禁用。有什么方法可以隐藏它吗?@JosieP我可以成功隐藏粘贴选项,但无法隐藏特殊粘贴。