use macro on a protected sheet

G

Guest

If i protect a worksheet the macro is not executing. it is giving error
message as
Run-Time Error 1004
You cannot use this command in a protected sheet.

kindly suggest the procedure to execute the macro in a protected sheet. i
want to protect some cells in the sheet from being uptaion.
 
J

JulieD

Hi

you'll need to uprotect the sheet at the start of the macro and protect it
again at the end
e.g.

sub mymacro()

activesheet.unprotect ("pwd")
'current code

activesheet.protect ("pwd")
end sub

where pwd is your password

Cheers
JulieD
 
T

Tony

If you are protecting the worksheet from the VBA code you
might try this:

Dim x as Boolean

x = Worhsheets(1).Protect_
(DrawingObjects:=True, Contents:=True, _
Scenarios:=True, UserInterfaceOnly:=True)

The last arg sets the protection so that a macro can alter
the sheet but a user cannot.

Hope this helps

Tony
 

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