Previously working replace macro gave error today

A

Al

A macro which has operated properly many times in the past halted with an
error this morning. The debugger indicated line 10 below as the error.
After trying to determine why, I did a manual find/replace and the
replace window came up with use wildcards checked. I guess that the last
replace I did yesterday (different document) used wildcards and Word
remembered this setting. How do I unset this in the macro? I am using
Word 2002.

1 Selection.WholeStory
2 Selection.Find.ClearFormatting
3 Selection.Find.Replacement.ClearFormatting
4 With Selection.Find
5 .Text = "^l"
6 .Replacement.Text = " "
7 .Forward = True
8
9 End With
10 Selection.Find.Execute Replace:=wdReplaceAll
11 With Selection.Find
12 .Text = " ^p"
13 .Replacement.Text = "^p"
14 .Forward = True
15
16 End With
 
J

Jonathan West

Hi Al,

These articles will show you what you need to do.

Clear settings from Find and Replace dialog to prevent unexpected results
from future Find or Replace operations
http://www.word.mvps.org/FAQs/MacrosVBA/ClearFind.htm

Flush bad karma from Word's find facility after an unsuccessful wildcard
search
http://www.word.mvps.org/FAQs/MacrosVBA/FlushFR.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Al,

use

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
' plus some more if needed !
.Execute
End With
End Sub

always before serching and (!) after as well.


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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