I have a program I developed where several of the spreadsheets are protected. I had been using the UnProtect/Protect method in my code but was having a problem with sequencing with this method that was causing my code to fail. I researched online and discovered the UserInterfaceOnly option. I added code to the Workbook_Open() module for the specific Worksheets that needed to be Protected but hopefully would allow my programming modules to work.
Here are the lines of code in the Workbook_Open() module that set the protection:
Sheets("Customer Report Controls").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Control Limits").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Setup").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Setup Controls").Protect Password:="WtMaster", UserInterFaceOnly:=True
I manually checked the Worksheets after adding this code and each of the listing Worksheets are protected as expected.
I am trying to access a cell on the "Setup" Worksheet that has a Range name of "Date_Format"
The program fails when the following line of code attempts to execute:
Application.Goto Reference:="Date_Format"
The error I receive is:
Run-time error '1004':
Method "Goto' of object '_Application' failed
I can manually Unprotect the "Setup" Worksheet and the code runs without a problem.
I have spent a good bit of time trying to research the issue to no avail. I really don't want to go back and UnComment all my Unprotect and Protect code if at all possible!
Let me know if anyone can help.
Here are the lines of code in the Workbook_Open() module that set the protection:
Sheets("Customer Report Controls").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Control Limits").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Setup").Protect Password:="WtMaster", UserInterFaceOnly:=True
Sheets("Setup Controls").Protect Password:="WtMaster", UserInterFaceOnly:=True
I manually checked the Worksheets after adding this code and each of the listing Worksheets are protected as expected.
I am trying to access a cell on the "Setup" Worksheet that has a Range name of "Date_Format"
The program fails when the following line of code attempts to execute:
Application.Goto Reference:="Date_Format"
The error I receive is:
Run-time error '1004':
Method "Goto' of object '_Application' failed
I can manually Unprotect the "Setup" Worksheet and the code runs without a problem.
I have spent a good bit of time trying to research the issue to no avail. I really don't want to go back and UnComment all my Unprotect and Protect code if at all possible!
Let me know if anyone can help.
Last edited: