0
votes
  1. The Customer number on the invoice can be located using the regex pattern "(?<=Payee Account:).*" which results in TEST-02 or AU--T-01 or COM-P-10 or NG--R01, and many more iterations of dash placements within the Customer Code.

  2. The challenge I have is replacing dashes within this pattern.("(?<=Payee Account:).*") I have tried many iterations of solutions offered on stackoverflow but none seem to offer a Find and Replace within a regex.pattern.

The follwoing code is non-functional but is a collection of different solutions brought together. I need guidance with proper syntax and coding.

Sub aCustCode()

Dim str As String Dim regex As Object Set regex = CreateObject("VBScript.RegExp")

Dim matchesVal As Object Dim CustCodeRegexPattern As String CustCodeRegexPattern = "(?<=Payee Account:).*"

With regex
    .pattern = CustCodeRegexPattern
    .Global = True
    .IgnoreCase = True
    .MultiLine = True
    
    str = Selection.Text

End With

With Rng
    .Find.Text = "-"
    .Find.Replacement.Text = "_"
    .Find.Execute Replace:=wdReplaceOne
End With

End Sub

Thank-you in advance for your solutions.

Rene