Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic Run Time Error 5692 & .MatchWildcards = False

Status
Not open for further replies.

timtak2

Instructor
Mar 30, 2004
7
JP
thread707-1446480
I had the following
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "?^p"
.Replacement.Text = "?{^0013"
End With
Selection.Find.Execute Replace:=wdReplaceAll

Which was intended to add a curly bracket after end of line question marks but I got the VBA Run time error 5692.

I searched the net to very little avail other than the above thread where the question but not the solution was mentioned. The solution was to add
.MatchWildcards = False
i.e. to become
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "?^p"
.Replacement.Text = "?{^0013"
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

I guess that wildcards are on by default. I am not sure why wildcards should throw an error but I do know that it would have found the wrong string (all end of line characters?) and that in fact just gave an error.

I report hereabove a (if unexplained) solution.
 
Howdy!

Your problem is easily explained and solved:
Code:
      .Text = "?^p"
       .Replacement.Text = "?{^0013"
If MatchWildcards is set TRUE, then the code for both Finding and Replacing hard returns is ^013 (three digits), whereas the question mark denotes ANY ONE character and the curly bracket opens the set of match numbers, e.g. {1,2} (1 or 2 matches). To denote the specific characters, you must add a backslash before as an escape character.

If MatchWildcards is set FALSE, the code is ^p and question marks and curly brackets are treated as such.

So finding a question mark followed by paragraph marker and adding a curly bracket WITHOUT Wildcards would be
Code:
       .Text = "?^p"
       .Replacement.Text = "?{^p"
       .MatchWildcards = False

WITH wildcards, it would be
Code:
       .Text = "\?^013"
       .Replacement.Text = "\?\{^013"
       .MatchWildcards = True

As you are dealing with a fixed set of characters, there is no need for wildcards anyhow and your solution would be the first one.

OK?
;-)

Cheers,
MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thanks very much. That is clear.

Hopefully now when people search for Error 5692 then they will, in due course of time, be directed here where it will be made clear to them.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top