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

Re: Previously working replace macro gave error today by Jonathan

Jonathan
Thu Jul 21 10:33:50 CDT 2005

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

"Al" <pat-al.serrano@worldnet.att.net> wrote in message
news:Xns969A55B9F6441patalserranoattnet@138.126.254.210...
>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


Re: Previously working replace macro gave error today by Helmut

Helmut
Thu Jul 21 10:50:46 CDT 2005

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"