ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Running Macros in protected workbook (https://www.excelbanter.com/excel-worksheet-functions/9418-running-macros-protected-workbook.html)

petunia

Running Macros in protected workbook
 
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

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


"petunia" wrote in message
...

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




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

"Paul B" wrote:

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


"petunia" wrote in message
...

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





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




"petunia" wrote in message
...
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

"Paul B" wrote:

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


"petunia" wrote in message
...

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








All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com