vba 右键单击 Excel 中禁用的工作表标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/494926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:35:59  来源:igfitidea点击:

Right click on sheet-tabs disabled in Excel

excelvbaexcel-vbaright-click

提问by Kablam

I used this vba code in the ThisWorkbook module to disable the right click menu in an Excel workbook.

我在 ThisWorkbook 模块中使用了这个 vba 代码来禁用 Excel 工作簿中的右键单击菜单。

Private Sub Workbook_Activate()
   With Application.CommandBars.FindControl(ID:=847)
      .Visible = False
   End With
End Sub

Private Sub Workbook_Deactivate()
   With Application.CommandBars.FindControl(ID:=847)
      .Visible = True
   End With
End Sub

Works like a charm.
Problem is, I can't access the right click menu on tabs in ANY workbook now. The second part of the code is supposed to turn it back on, I assumed? Yet it doesn't.

奇迹般有效。
问题是,我现在无法访问任何工作簿中选项卡上的右键单击菜单。我假设代码的第二部分应该重新打开它?然而它没有。

Even when I remove the code entirely, no workbook, not even a new one, has a menu when I click right on one of the tabs.

即使我完全删除了代码,当我在其中一个选项卡上单击鼠标右键时,没有工作簿,甚至是新的工作簿都没有菜单。

Is there a general vba codesnippet that "resets" excel maybe? Or a general "enable all menus" thing?

是否有一个通用的 vba 代码片段可以“重置”excel?还是一般的“启用所有菜单”?

REVISION: This code posted here doesn't disable the rightclick menu, it removes the "delete" option from that specific menu.

修订:此处发布的此代码不会禁用右键单击菜单,它会从该特定菜单中删除“删除”选项。

回答by Kablam

omg

我的天啊

Application.CommandBars("Ply").Enabled = True

-.-
Started googling different keywords after the last edit and BAM.

-.-
在最后一次编辑和 BAM 之后开始使用谷歌搜索不同的关键字。

回答by Mikael Katajam?ki

Late again as usual, but tackled with the same problem today. Here's the solution to get your right-click functionality back:

再次像往常一样迟到,但今天解决了同样的问题。这是恢复右键单击功能的解决方案:

Option Explicit
'
Sub tester()
    '
    Dim cBar As CommandBar
    '
    For Each cBar In CommandBars
        Debug.Print cBar.Name
        If (cBar.Type = msoBarTypePopup) Then cBar.Enabled = True
    Next
End Sub

回答by Marxcr

Also note that the below also exist. Some macro from work had them all disabled in my Excel.

另请注意,以下内容也存在。工作中的一些宏在我的 Excel 中将它们全部禁用。

Application.CommandBars("Cell").Enabled = True
Application.CommandBars("Row").Enabled = True
Application.CommandBars("Column").Enabled = True