Reputation: 27
Here is the code which was working yesterday:
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
It should search for "Error! Reference source not found.", and if the document contains that string then it should throw a warning and ask the user if they want to continue.
Worked yesterday, now it's throwing
"The Find What text contains a Pattern Match expression which is not valid"
on .Execute FindText
.
Usually this error comes from something like a wildcard search with an unclosed set of brackets or something.
(I have tried turning it off and on.)
Upvotes: 0
Views: 725
Reputation: 13515
The problem is most likely that you've previously done a wildcard Find and have not re-set that (despite what you say to the contrary):
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
Upvotes: 1