Removing dialogs from Word Macros

F

Fred G

I have a few recorded Word macros to clean up text for for a magazine.
These involve a number of Search and Replace actions. Annoyingly Word
asks if I want to search from the beginning of the Document after each
Search and Replace. Hitting N for No dismisses the dialogue and Word
goes on to the next Search. Fine, but I have lots of these in the
macro.

Does anyone know how to tell Word to not display these dialogues when
re-running a Macro?
 
J

John McGhie

Hi Fred:

The short answer is "Set your .Wrap property to wdFindContinue"

Here's a sample that search/replaces TOC styles 1 to 9 in a document to
format the tab leaders a light grey. Note that there are two "With"
statements. The first sets up all of the non-changing stuff, the second
sets only the parameters that are going to change for each search, and
actually executes the search.

Sub ReplaceTabLeaders()
'
' Macro1 Macro
' Macro recorded 04/11/2004 by John McGhie
'
Dim n As Integer

With Selection.Find
.ClearFormatting
.ParagraphFormat.Borders.Shadow = False
.Replacement.ClearFormatting
.Replacement.Font.Color = wdColorGray25
.Text = "^t"
.Replacement.Text = "^t"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

With Selection.Find
For n = 1 To 9
.ClearFormatting
.Style = ActiveDocument.Styles("TOC" & Str(n))
.Execute Replace:=wdReplaceAll
Next ' n
End With
End Sub


I have a few recorded Word macros to clean up text for for a magazine.
These involve a number of Search and Replace actions. Annoyingly Word
asks if I want to search from the beginning of the Document after each
Search and Replace. Hitting N for No dismisses the dialogue and Word
goes on to the next Search. Fine, but I have lots of these in the
macro.

Does anyone know how to tell Word to not display these dialogues when
re-running a Macro?

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
K

Klaus Linke

[...] Hitting N for No dismisses the dialogue [...]
Thank You, Thank You, Thank You. It works wonderfully well!

If you always answered "No", you should set it to ".Wrap = wdFindStop".
It means Word won't search the rest of the document if you had selected
some text, or won't start searching at the top if you have reached the end
of the document.

Regards,
Klaus
 

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