Search Conditions

D

dsc

When I try to use wildcards in a search and replace from a macro,

With ActiveDocument.Content.Find

.Text = "<" & TermString & ">"

.Replacement.Text = StandardString

.Forward = True

.Wrap = wdFindContinue

.Format = True

.MatchCase = True

.MatchWholeWord = True

.MatchByte = True

.MatchAllWordForms = False

.MatchSoundsLike = False

.MatchWildcards = True

.MatchFuzzy = False

.Execute Replace:=wdReplaceAll

End With



I get error 5590 on "Execute Replace:=wdReplaceAll".



Anybody got any ideas?
 
A

Anne Troy

I believe that would be:
Selection.Find.Execute Replace:=wdReplaceAll

<-*-><-*-><-*-><-*-><-*-><-*-><-*-><-*->
Hope this helps!
Anne Troy (better known as Dreamboat)
Web: New! www.VBAExpress.com
<-*-><-*-><-*-><-*-><-*-><-*-><-*-><-*->
 
D

dsc

Actually, nothing is selected. The macro goes through a file looking for
words in field 1 of an Access data base and replacing them with the contents
of field 2. That's why I'm using variables. I put the contents of field 1
into string variable TermString and the contents of field 2 into
StandardString.
 
D

dsc

It looks like setting .MatchWildcards = True causes an error with .Execute
Replace:=wdReplaceAll
 
D

Doug Robbins - Word MVP

Use an Update Query in Access.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

dsc

Use an Update Query in Access.

The problem isn't in Access, though. The problem is with Word, for instance,
finding the CAR within the word hydrocarbon, and giving me
hydroautomobilebon.

It seems as though setting
.MatchCase = True
.MatchWholeWord = True
.MatchByte = True
should keep that from happening, but these parameters, as far as I can tell,
have no effect whatsoever on a word search from VBA.

It seems that the wildcard search capabilities of VBA may be so buggy that
there is no solution to this problem. I tried a couple of proposed solutions
at links you provided and other places, but nothing worked.

Setting MatchWildcards = True results in error 5590 in the command .Execute
Replace:=wdReplaceAll, and nothing I've found allows the macro to run.
 
D

Doug Robbins - Word MVP

If I run a macro containing:

Dim TermString As String, StandardString As String
TermString = "car"
StandardString = "automobile"
With ActiveDocument.Content.Find
.Text = "<" & TermString & ">"
.Replacement.Text = StandardString
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchByte = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With

on a document that contains the following text:

The problem isn't in Access, though. The problem is with Word, for instance,
finding the car within the word hydrocarbon, and giving me
hydroautomobilebon

The result is

The problem isn't in Access, though. The problem is with Word, for instance,
finding the automobile within the word hydrocarbon, and giving me
hydroautomobilebon

No Visual Basic error message and the word hydrocarbon is left unchanged.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

dsc

"Doug Robbins wrote
If I run a macro containing:

Yes, your macro works. However, my macro repeats that operation a number of
times, and crashes before completion.

The other day, I was getting the error message with no replacements
appearing in my doc.

Today, using a different doc, I am getting some replacements in my doc
before the macro terminates with error 5560, vice 5590.

Setting MatchWildCards to False allows the macro to complete without error.
Setting MatchWildCards to True causes the macro to terminate early with
error 5560. The other day it was 5590.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top