How to allow VBA-based hide/unhide of worksheets to continue working while the whole workbook is protected?

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hello,

I wrote the following code to automatically hide/unhide the relevant worksheets based on a dropdown menu selection. However, I also want to protect the workbook so that my "Control" worksheet (not in the code) can never be unhidden and also so that no users can delete any of the worksheets.

Private Sub Worksheet_Change(ByVal Target As Range)
If ['Info-Setup'!$J$10] = "Template style" Then
Sheets("Input").Visible = True
Sheets("Plates-Input").Visible = False
Sheets("Plates-Data").Visible = False
Sheets("Validity").Visible = True
Sheets("Excel").Visible = True
ElseIf ['Info-Setup'!$J$10] = "Plate style" Then
Sheets("Input").Visible = False
Sheets("Plates-Input").Visible = True
Sheets("Plates-Data").Visible = True
Sheets("Validity").Visible = True
Sheets("Excel").Visible = True
ElseIf ['Info-Setup'!$J$10] = "" Then
Sheets("Input").Visible = False
Sheets("Plates-Input").Visible = False
Sheets("Plates-Data").Visible = False
Sheets("Validity").Visible = False
Sheets("Excel").Visible = False
End If
End Sub



After I locked the workbook, unfortunately my dropdown menu stopped working; upon selecting any of the dropdown options, I got the debug message.

Is there any way to deal with this situation?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I found a partial workaround for this situation (without enabling "protect workbook"):

Part 1) I found code online that prevents deleting of worksheets

Part 2) To prevent unhiding of my Control worksheet, I set its visible property to "very hidden"

Part 3) I put a password for code editing, so nobody can open the editor and reverse my above-mentioned protections.

However, I have so far not been able to find any working code that would prevent renaming of worksheets. I tried these two suggestions, but neither worked for me (perhaps they were good for older versions of Excel?):

The other issue would be to prevent moving the worksheets around, which I wasn't able to find good code for either, although I'm not particularly concerned about moving of worksheets as this will not effect their functionality (but it might make it a bit less intuitive for some users to find their way around the worksheets).

Not sure if there are any other aspects to "protect workbook" that I should be thinking about (besides "deleting", "unhiding", "renaming", and "moving" of worksheets)?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top