Is there a way automatically to add Option Private Module
to all modules in VBA?
Something like the automatic adding of Option explicit
when we mark the checkbox in the Extras>Option>editor for declaration of variables?
Because going through all modules and writing it manually somehow seems like the only option.
Sub-question:
If you have to add Option Private Module
to all modules in 10 applications what would you do?
At first I was thinking to use a simple Replace and to replace the Option Explicit
with Option Explicit ^p Option Private Module
, but it would replace it in the classes as well and I have to delete it from there.
Ideas to save some 30 minutes here?
This should get you most of the way there, and this example works for all open, unprotected projects. If you need to modify protected projects, just unprotect them first.
Remember that you'll need to explicitly save changes to any add-ins.
See the inline comments for the rationale behind various checks
Edit from OP(@vityata): I have decided to add to your answer my updated one (I hope you do not mind). It is with late binding, thus no libraries are needed:
Took me a little longer to modify exisitng code of mine, you could try the following code below to repalce all places of "Option Explicit" with "Option Private Module".
Code