Lock project for viewing - VBA

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
mak345Asked:
Who is Participating?
 
Martin LissOlder than dirtCommented:
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.
0
 
Martin LissOlder than dirtCommented:
ActiveSheet.Protect Password:="Secret"
0
 
ProfessorJimJamCommented:
do you mean this type of locking?untitled.png
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Roy CoxGroup Finance ManagerCommented:
You can protect the worksheet modules separately from the workbook. Locking a VBA Project works only on the whole workbook.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
0
 
Martin LissOlder than dirtCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.