Is there a way to use regex expressions within the VBA editor's find and replace tool?
for example: I've turned pattern matching on but my regex expressions do not seem to work at all.
Is there a way to use regex expressions within the VBA editor's find and replace tool?
But, if you want to replace something per Sub
, you can loop all Subs, check for Private
and add something like this:
For Each objComp In objPro.VBComponents
If objComp.Type = 1 Then
strText = objComp.CodeModule.Lines(1, UP_TO_LINE)
If InStr(1, strText, PRIVATE_MODULE) = 0 Then
objComp.CodeModule.InsertLines 2, PRIVATE_MODULE
End If
End If
Next objComp
The whole code is from this answer - https://stackoverflow.com/a/41612479/5448626
Playing with the VBEditor & VBA is quite interesting: