以下代碼是迄今爲止提到的。我也爲正則表達式5.5設置了參考。VBA正則表達式:匹配不顯示任何值
但是,匹配值根本不顯示,我在這裏丟失了什麼?
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
能否請您在'wb.Worksheets(1).Cells提供值(2,4).Value'所有的初始化語句都走了,你想解析。 – Santosh
感謝您的提醒,我忘記了包括: 123456-S1234567F-獎學金錶格 – user1043870
你想從'123456-S1234567F-Scholarship Form'字符串中得到什麼? – Santosh