Protecting Sheets, automatically protects the workbook

G

Guest

I am trying to protect particular sheets in a workbook.
Code used:
Private Sub Workbook_Open()
Password = "1234"
Sheets("MasterData").Protect Password, True, True, True
Sheets("Unassigned Requests").Protect Password, True, True, True
End sub

And i unprotect using
Sheets("Unassigned Requests").Unprotect Password

This protects my entire workbook when i open it the next time. How to avoid
this?
 
D

Dave Peterson

First, you have another active thread.

Second, the code you included here doesn't protect the workbook--it protects
those worksheets.

Excel has various levels of protection.

Worksheet protection (tools|protection|protect sheet) -- to keep users from
changing locked cells and changing formatting.

workbook protection (tools|protection|protect workbook) -- to keep users from
inserting/deleting worksheets (structure) or to keep the users from changing the
window sizes (Windows)

VBA Project protection -- to keep your code from prying eyes.

And workbook protection (again). This can be used to prevent users from even
opening the workbook--or only allow the user to open in readonly mode.

Your code does that worksheet protection stuff.
 
G

Guest

Private Sub Workbook_Open()

Sheets("masterdata").protect Password = "1234"
Sheets("Unassigned Requests").Protect Password="1234"
End sub

And i unprotect
Sheets("Unassigned Requests").Unprotect Password ="1234"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top