Suppressing macro display in Word 2003 macro

A

Alan Stancliff

Suppose one writes a macro that performs tasks that manually would
necessitate dialog boxes, such as a search and replace? Is it possible to
turn off the display at the start of the macro and turn it back on at the end
of the macro with the editor screen refreshed?

Regards,

Alan
 
J

Jay Freedman

Suppose one writes a macro that performs tasks that manually would
necessitate dialog boxes, such as a search and replace? Is it possible to
turn off the display at the start of the macro and turn it back on at the end
of the macro with the editor screen refreshed?

Regards,

Alan

It isn't usually necessary to do anything about the dialog. The macro simply
carries out the action that the dialog would start, without ever showing the
dialog. The key here is that you cannot _record_ such a macro, because you'd be
recording the showing of the dialog; instead you have to learn to write macros
ab initio, or at least learn to modify recorded macros.

For your example of a replace action, the code would look something like

Sub demo()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "find me"
.Replacement.Text = "found this"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
End Sub

It could get more or less complicated from here. The point is, when this macro
runs, it doesn't show the Replace dialog, so there's no need to look for a way
to hide the dialog.

The fun part is when you want to show the dialog, but not do the associated
action (or at least, not immediately). Then you need to use the Dialogs
collection, and you should look up the VBA help topics about the .Show and
..Display methods of the Dialog object.
 
A

Alan Stancliff

Hi Jay,

What I had been doing is recording bits and pieces and then trying to
assemble them. From your response, it is becoming obvious to me that the only
way I could do this with any macros I write is to write them from scratch,
using the commands built into VBA. In other words, I have to learn a lot more
to be able to do this.

I'll look around for some documentation on line for beginners like me. I saw
a few such links on your web site.

Thanks for the good energy.

Regards,

Alan
 

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