×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Visual Basic Run Time Error 5692 & .MatchWildcards = False

Visual Basic Run Time Error 5692 & .MatchWildcards = False

Visual Basic Run Time Error 5692 & .MatchWildcards = False

(OP)
thread707-1446480: Help using VBA in word
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.

RE: Visual Basic Run Time Error 5692 & .MatchWildcards = False

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?
winky smile

Cheers,
MiS

"We had to turn off that service to comply with the CDA Bill."
- The Bastard Operator From Hell

RE: Visual Basic Run Time Error 5692 & .MatchWildcards = False

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close