How to get a macro to run that uses a protected sheet

G

Guest

I would like to create some simple macros (e.g. selecting criteria within an
autofilter and then printing the result) but I would also like to protect the
sheet that contains the Autofiltered data.

When I turn protection on the macro fails.

Is there any way to run macros AND protect sheets?

Thanks
 
G

Guest

In code you need to unprotect then execute your code and then reprotect.
There is no way around it...
 
G

Guest

Have then macro turn protection off and then when done turn it back on:

Sub MyMacro()

Sheets("Sheet1").Unprotect
' Run the rest of your code here
Sheets("Sheet1").Protect

End Sub
 
T

Tom Ogilvy

Activesheet.Protect UserInterfaceOnly:=True
ActiveSheet.EnableAutofilter = True

the autofilter must already exists, but you can change the criteria.

In xl2002 and later, I believe you have to supply the password (if there is
one) when you do the Protect command.
 

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