0

Here is my code:


Option Explicit

Sub parseInvocationParm(parmInvocationParm)

'   https://www.automateexcel.com/vba/regex/

    MsgBox "In parseInvocationParm, the value of parmInvocationParm is " & parmInvocationParm
    
    Dim regExObject As New VBScript_RegExp_55.RegExp
 
    regExObject.Pattern = "^.*\/e(.*)"
    regExObject.Global = False
 
    Dim Replacement As String
    
    Replacement = "$1"
    
    If regExObject.Test(parmInvocationParm) Then
    
        regExObject.Replace (parmInvocationParm, Replacement)
        
    Else

        MsgBox "The regExObject.Test(parmInvocationParm) test failed to match"
    
    End If

End Sub

Without even getting to execute this code, when I enter it into the VBA editor window the editor highlights the instruction regExObject.Replace (parmInvocationParm, Replacement) and displays a message Compile Error: Expected =

I get the same error condition no matter how I define the replacement string, e.g. just a simple text string such as my first name with no backreferences. I've looked at numerous examples on the web of the regExObject.Replace method and they all seem to be very simple examples of using two strings as the two parameters, and as far as I can tell my code is very consistent with those examples, yet I keep getting this compile error.

Can anyone see what is wrong?

Thanks tremendously in advance.

1 Answer 1

1

Remove the parenthesis from this part of your code:

regExObject.Replace (parmInvocationParm, Replacement)

It should be:

regExObject.Replace parmInvocationParm, Replacement

If you keep the parenthesis, then you must use Call statement:

Call regExObject.Replace (parmInvocationParm, Replacement)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .