Running Macros in protected workbook

P

petunia

I have a macro in a protected workbook that won't work correctly with it
protected, how can I get the macro's to work
 
P

Paul B

petunia, you could unprotect the sheet run your code and then protect the
sheet like this

ActiveSheet.Unprotect password:="123"

'you code here

ActiveSheet.Protect password:="123"



or protect it with user interface only, like this then the macros will run,
this will have to be set each time the workbook is opened

ActiveSheet.Protect UserInterfaceOnly:=True, password:="123"
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
P

petunia

when I send this to someone, I don't want them to make changes to the other
sheets, will this allow them to run the macro's but not make changes of any
other kind, and keep the rest of the sheet protected
 
P

Paul B

Petunia, Yes, the sheet will be protected in the same way as if you
protected it yourself, the user will not know that the sheet is being
unprotected and then protected when the macro is run so the sheet will be
locked any time the macro is not running, if you use the user interface only
this will let the macros run on a protected sheet.

You may want to reference a sheet like this instead of the active sheet like
this

Worksheets("sheet1").Protect UserInterfaceOnly:=True, password:="123"

Be aware that sheet protection is very weak in excel, but it will keep
someone form accidentally messing up your data.



You may want to protect the VBA project so others will not see the password
in it, from your workbook right-click the workbook's icon and pick View
Code. This icon is to the left of the "File" menu this will open the VBA
editor, in the left hand window right click on your workbook name and select
VBA project properties, protection, check lock project for viewing and set a
password. Press Alt and Q to close this window and go back to your workbook
and save and close the file.
--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 

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