excel - Excel VBA 返回“编译错误:预期:表达式”
问题描述
我正在尝试将一个值设置为另一个函数的返回值,但我陷入了这一行:
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
解决方案
您必须''
用引号替换撇号""
,否则 VBA 会将其解释为注释。
更改此行:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,'([^.]+)')
有了这个:
Set tempMergeValue = TypeRegxFunc(MyRange.Rows(iCounter).Columns(1).Value,"([^.]+)")
它会起作用的。
我希望这有帮助。
推荐阅读
- ansible - 在 ansible 中找到的目录上添加粘性位
- java - Moving more than one node simultaneously in contiki-os (Mobility)
- ethereum - Web3 getTransaction returns null even in geth same
- storage - AnyLogic:将两个代理同时移动到托盘架中
- python - Nested custom directives in sphinx
- solana - 我想知道导致 solana 传输错误
- flutter - How to make an API request with selectableDayPredicate of flutter datePicker
- python - pandas如何将上组的部分数据添加到下组的开头
- java - how to receive data in one activity in communication with a bluetooth module using service
- excel - How to test for instance of httpheader using vba