Excel VBE Multiline Search And Replace

I'm a full time Excel developer.

That means I spend quite some time writing code in the Visual Basic Editor (VBE).
I don't maintain a real code library, but I do copy lots of code from previous projects into new ones.

Whereas the VBE is quite a nice application to write code in, it does lack some functionality I needed a couple of weeks ago: the ability to do a search and replace operation on multiple lines of code in one go.

For example, many routines in my projects contain an error handling mechanism of some sort. These may look like this:

TidyUp:
    On Error GoTo 0
    Exit Sub
locErr:
    If ReportError(Err.Description, Err.Number, "DoFindReplace", "Module modMain")=vbRetry then
        Resume
    Else
        Resume Next
    End If

Now what if I want them to look like this:

TidyUp:
    On Error GoTo 0
    Exit Sub
locErr:
    Select Case ReportError(Err.Description, Err.Number, "DoFindReplace", "Module modMain")
    Case vbRetry
        Resume
    Case vbIgnore
        Resume Next
    Case vbAbort
        Resume TidyUp
    End Select

I wanted a tool that would let me replace the part after the IF statement with the part after the Select Case statement.
Well, here is my first go at it:

Excel VBE Multiline Search And Replace

And here is a screenshot:

Leave a comment