We help IT Professionals succeed at work.

Lock project for viewing - VBA

mak345
mak345 asked
on
I know it is bad practice but I have little choice but to use SendKeys in the situation I am in.

I have a master program where I am running a loop through several other sheets where I import code into its vba editor.  This part works fine.  But I want to add a step where it then protects each sheet by locking its project for viewing.  But when I run throguh the code, it tries to protect the master program and not each individual sheet.

How can I tell it to protect the other sheets?  It this possible?

Thanks
Comment
Watch Question

Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
ActiveSheet.Protect Password:="Secret"
"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Also if the sheets are in another workbook and the code you are adding to each sheet is the same you can use a template that already contains the code.
Professor JMicrosoft Excel Expert
Top Expert 2014

Commented:
do you mean this type of locking?untitled.png
Roy CoxGroup Finance Manager

Commented:
You can protect the worksheet modules separately from the workbook. Locking a VBA Project works only on the whole workbook.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
If you use a reference to the workbook or sheet to protect instead of Active... you will be able to work while debugging in your master.
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015