Protecting a worksheet

A

Anthony

Hi all

I have a worksheet that contains aprox 8 buttons that each run a macro to
complete certain tasks from displaying userforms to moving to another
worksheet.

Rather than adding code into each macro, is there a way to protect the
worksheet, unprotect whilst any macro is run then protect it again once the
macro is complete?

thanks
 
J

Jim Thomlinson

You will have to add code to each button but you can make the code very short
by addin two procedures to do the protection and unprotection. Call the
unprotectall macro at the start and the protectall at the end of each command
button procedure...

sub UnProtectAll
dim wks as worksheet

for each wks in thisworkbook.worksheets
wks.unprotect Password:="Tada"
next wks
End sub

sub ProtectAll
dim wks as worksheet

for each wks in thisworkbook.worksheets
wks.protect Password:="Tada"
next wks
End sub
 

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