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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.