vba,错误消息,vba引用,正则表达式



我收到一条错误消息。

Compile error: Method or data member not found
Line causing Error: It highlights Sub Macro1() and after I click ok, it selects: .MultiLine = 
I just saved it as a macro enabled workbook. Now getting: Compile error. Method or data member not found. Error goes to same place.

为什么代码收到此错误消息?我使用的是VBA引用:Microsoft VBScript正则表达式1.0和Microsoft VBScript常规表达式5.5。我正在使用VBA,因为我需要在电子表格中使用Regex。我需要将3_CELL_VALUE或2_CELL_VALVE之类的内容更改为1_CELL_VALUE来准确计数我的数据。

Sub Macro1()
Dim strPattern As String: strPattern = "[0-9]_CELL_VALUE"
Dim strReplace As String: strReplace = "1_CELL_VALUE"
Dim regEx As New RegExp
Dim strInput As String
Dim Myrange As Range
Set Myrange = Worksheets("Data").Range("$A$1:$A$9999")
For Each cell In Myrange
If strPattern <> "" Then
strInput = cell.Value
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
MsgBox (regEx.Replace(strInput, strReplace))
Else
MsgBox ("Not matched")
End If
End If
Next
End Sub

有两个版本的库Microsoft VBScript Regular Expressions、1.0和5.5。您收到的错误消息显示您正在使用旧的1.0版本。把它换成新版本根本不要使用1.0。添加引用的顺序可能导致早期版本隐藏了较新版本。

最新更新