"Pattern Match expression not valid" .Execute FindText 错误

"Pattern Match expression not valid" error for .Execute FindText

这是昨天运行的代码:

Sub TestError()

Dim Error As Integer

    With Selection.Find
      .ClearFormatting
      .Font.Bold = True
      .Execute FindText:="Error! Reference source not found."

        If .Found = True Then
           Error = MsgBox("Reference Source error detected - continue with macro?", 4)
              If Error = 7 Then
              Exit Sub
             End If
         End If

    End With

End Sub

它应该搜索“错误!找不到参考源。”,如果文档包含该字符串,那么它应该发出警告并询问用户是否要继续。

昨天干的,现在扔了

"The Find What text contains a Pattern Match expression which is not valid"

.Execute FindText

通常此错误来自于带有未闭合括号集的通配符搜索之类的东西。

(我试过关闭再打开。)

这个问题很有可能是你之前做过wildcard查找但没有重新设置(尽管你说的相反):

Sub TestError()
Dim Error As Long
With Selection.Find
  .ClearFormatting
  .Font.Bold = True
  .MatchWildcards = False
  .Text = "Error! Reference source not found."
  .Execute
  If .Found = True Then
    Error = MsgBox("Reference Source error detected - continue with macro?", 4)
    If Error = 7 Then Exit Sub
  End If
End With
End Sub