I found Siddharth Rout's great code for adding a new sheet and code for it, but my need is a touch different.
I want to add Activate code to an existing worksheet. I tried substituting that sheets name in place of using the .Name
property, dropping the
Set ws = Worksheets.Add
and replacing ws.Name
with my existing sheets name, "Work". It bombs at that point.
Inspection of the ws object using the code in the existing example shows the property Name of the ws object to be a simple string, so not being able to use my existing sheet's name there instead is baffling me.
Why:
The existing sheet "Work" is initially created with no Activate code. It is used heavily through many steps in this multisheet multifunction system and I want to prevent the user from changing it if he selects it manually -- there are reasons to let him look at it, to make decisions, during the pauses for his interaction -- yet leave it unprotected otherwise as my VBA bounces to and from it.
So, I want to insert Activate code that protects the sheet -- the Deactivate code that removes the protection will can be permanent part of the sheet, won't hurt -- and so protect the sheet whenever the user decides to look at it manually, whenever my VBA allows user interaction, then remove/alter that code via its Deactivate when the user leaves the sheet and returns to the interactions, so it's normally free for my code's use otherwise without the protection being added each time my code switches to it.
I'll create and leave the Unprotect deactivate code there permanently -- won't hurt -- so it isn't altering itself (which is a horrifying no-no). How?
Sorry for all the words. My hour of google search for "self modifying code" in VBA found no good answers.