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.