Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2005

Tip: Looking for answers? Try searching our database.

Previously working replace macro gave error today

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al - 21 Jul 2005 16:26 GMT
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
Jonathan West - 21 Jul 2005 16:33 GMT
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

Signature

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

>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.
[quoted text clipped - 20 lines]
> 15
> 16    End With
Helmut Weber - 21 Jul 2005 16:50 GMT
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"

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.