Я получаю сообщение об ошибке
«Переменная объекта или переменная блока не установлена»
установка функции для объекта RegEx, так что дело в том, чтоМне нужно проверить имя файла с этими шаблонами.
Я думаю, что Select case
это тоже неправильно.Я не знаю, как ее решить.
Do While xExcelFile <> ""
strPattern = GetPattern(newFileName)
With RegEx
.Pattern = strPattern 'error occurs here
End With
Select Case True
'go to next loop if the selected file and this workbook has the same name
Case xExcelFile = xWname
GoTo NextLoop
'filter by name pattern
Case RegEx.Test(newFileName)
Workbooks.Open fileName:=xSPath & xExcelFile 'open file
Case RegEx.Test(newFileName)
Workbooks.Open fileName:=xSPath & xExcelFile 'open file`
more operational code below
Это функция, которая ищет нужный шаблон, и я думаю, что он работает правильно
Function GetPattern(ByVal newFileName As String) As String
Dim strPattern As String
Static RegEx As Object
strPattern1 = "^([B]\d{3}\w{1,})"
strPattern2 = "^\d*\.\d{4}\w*"
If RegEx Is Nothing Then
' To speed the code up set the static RegEx object only once
Set RegEx = CreateObject("VBScript.RegExp")
End If
With RegEx
.Pattern = strPattern1
If RegEx.Test(newFileName) Then
strPattern = strPattern1
End If
.Pattern = strPattern2
If RegEx.Test(newFileName) Then
strPattern = strPattern2
End If
End With
GetPattern = strPattern
End Function