1

Is there a way to use regex expressions within the VBA editor's find and replace tool?

Screenshot of Find and Replace Tool

for example: I've turned pattern matching on but my regex expressions do not seem to work at all.

Vityata
  • 42,633
  • 8
  • 55
  • 100
ericauv
  • 160
  • 16

1 Answers1

1

Is there a way to use regex expressions within the VBA editor's find and replace tool?

  • Nope.

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:

http://www.rondebruin.nl/win/s9/win002.htm

Vityata
  • 42,633
  • 8
  • 55
  • 100
  • 1
    I believe the find and replace wildcards operate the same as with using the `Like` operator in VBA. For anything complex VBA is your best bet. – IvenBach Apr 18 '18 at 16:01