我在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
像魅力一样工作 问题是,我现在无法访问任何工作簿中选项卡上的右键菜单。 我假设代码的第二部分应该重新打开它?但事实并非如此。
即使我完全删除了代码,当我单击其中一个选项卡时,没有工作簿,甚至是新工作簿都没有菜单。
是否有一般的vba代码片段可以“重置”excel?或者一般的“启用所有菜单”的事情?
REVISION: 此处发布的此代码不会禁用右键菜单,它会从该特定菜单中删除“删除”选项。
答案 0 :(得分:4)
OMG
Application.CommandBars("Ply").Enabled = True
-.-
在上次编辑和BAM之后开始使用Google搜索不同的关键字。
答案 1 :(得分:2)
像往常一样晚了,但今天遇到了同样的问题。以下是恢复右键单击功能的解决方案:
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
答案 2 :(得分:0)
另请注意,下面也存在。工作中的一些宏在我的Excel中都被禁用了。
Application.CommandBars("Cell").Enabled = True
Application.CommandBars("Row").Enabled = True
Application.CommandBars("Column").Enabled = True