以下代码是我到目前为止提出的。我还设置了正则表达式 5.5 的参考。
但是匹配值根本没有显示,我在这里遗漏了什么吗?
Public Sub check()
Dim wb As Workbook
Set wb = ThisWorkbook
'Prepare a regular expression object
Dim myRegExp As New VBScript_RegExp_55.RegExp
Dim myMatches As MatchCollection
Dim myMatch As match
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "^\d{6,8}-[SFTG]\d{7}[A-Z]-([^-]+)$"
Set myRegExp = CreateObject("vbscript.regexp")
cellValue = CStr(wb.Worksheets(1).Cells(2, 4).Value)
'123456-S1234567F-Scholarship Form
If myRegExp.Test(cellValue) Then
Set myMatches = myRegExp.Execute(cellValue)
For Each myMatch In myMatches
MsgBox (myMatch.Value)
Next
Else
End If
End Sub