如何禁用工作表选项卡上的右键单击“删除”选项

如何禁用工作表选项卡上的右键单击“删除”选项

有没有办法禁用底部 Excel 工作表选项卡上的右键单击“删除”选项,以防止用户删除工作表。我知道保护工作表/工作簿将禁用此功能,但如果我想在保护或不保护的同时禁用它,该怎么办?

Application.CommandBars("Ply").FindControl(ID:=847).Enabled = False 

将禁用它,但如果工作簿/工作表有密码保护,则在取消保护时,该命令将被忽略,并且仍然可以删除工作表。

答案1

Option Explicit
' To Activate right click on tab - run the following
Private Sub Worksheet_Activate()
    Application.CommandBars("Ply").Enabled = False
End Sub

' To Deactivate right click on tab - run the following code
Private Sub Worksheet_Deactivate()
    Application.CommandBars("Ply").Enabled = True
End Sub

相关内容