Sub demo()
'想使用正則運算式進行資料處理,但是除錯的時候到正則submatches時候說物件不適用該屬性或方法,這是為什么呢?
給了s和用正則編輯器的結果,正則運算式應該對的
Worksheets("Sheet2").Activate
Dim s As String, myreg As Object, reg1 As Object, myreg1 As Object, i As Integer
i = 2
s = Worksheets("Sheet3").Cells(1, 1)
Set myreg = CreateObject("VBscript.regexp")
With myreg
.Global = True
.Pattern = "預訂\|.*?\|(.*?)\|(?:.*?\|){4}(.*?)\|(.*?)\|(.*?)\|(?:.*?\|){19}(.*?)\|(.*?)\|(.*?)\|"
End With
Set reg1 = myreg.Execute(s)
For Each myreg1 In reg1
Cells(i, 1) = reg1.submatches(0)
Cells(i, 2) = reg1.submatches(1)
Cells(i, 3) = reg1.submatches(2)
Cells(i, 4) = reg1.submatches(3)
Cells(i, 7) = reg1.submatches(4)
Cells(i, 6) = reg1.submatches(5)
Cells(i, 5) = reg1.submatches(6)
i = i + 1
Next myreg1

uj5u.com熱心網友回復:
第幾個reg1.submatches(?)出的錯?uj5u.com熱心網友回復:
老師老師,是我寫錯了,我寫成了reg1.應該是myreg1轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/30226.html
標籤:VBA
