无法设置隐藏的属性,受保护的工作表

我有一些VBA代码,可以在打开的单个工作簿中保护3张纸。

Private Sub workbook_open() Sheets("InputForm").Protect "password", UserInterfaceOnly:=True Sheets("Invoice").Protect "password", UserInterfaceOnly:=True Sheets("List").Protect "password", UserInterfaceOnly:=True End Sub 

我也有一些代码,显示/隐藏行是否是TRUE/FALSE在单元格N14

 Private Sub Worksheet_Calculate() If ActiveSheet.Name = "InputForm" Then Application.EnableEvents = False Sheets("Invoice").Rows("57:123").Hidden = Range("N14").Value Sheets("InputForm").Rows("57:94").Hidden = Range("N14").Value Application.EnableEvents = True Else Application.EnableEvents = False Application.EnableEvents = True End If End Sub 

当我使用命令button来执行一些复制/粘贴代码,我得到一个错误1004,无法设置范围类的隐藏属性。 debugging指向Sheets("Invoice")...行。

但是,如果我结束debugging器,再次点击button,似乎工作正常…?

任何帮助将不胜感激

您需要取消保护您的纸张,然后才能对其进行更改 – 即使使用VBA – 也是一样的概念。