我试图将一个值设置为另一个函数的返回值,但是却陷入了这一行:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,'([^.]+)')
TypeRegxFunc在这里
Function TypeRegxFunc(strInput As String, regexPattern As String) As String
Dim regEx As New RegExp
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = regexPattern
End With
If regEx.Test(strInput) Then
Set matches = regEx.Execute(strInput)
TypeRegxFunc = matches(0).Value
Else
TypeRegxFunc = "not matched"
End If
End Function
答案 0 :(得分:3)
您必须用引号''
代替撇号""
,否则VBA会将其解释为注释。
更改此行:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,'([^.]+)')
有了这个:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,"([^.]+)")
它将起作用。
我希望这会有所帮助。