How to Create a Macro that opens a Dialog Box

R

RKEvans

Help. Through user error I managed to wipe out all of my macros this
mornings. I have been able to recreate most of them, but I am having some
trouble with what should probably be the simplest one and I originally
created it so long ago that I cannot remember how I did it.

All I want the marco to do is open the Page Setup dialog box. I am
recording the macro as a button on the tool bar and I am using the following
key strokes: Alt, File, Page Setup. This is where the problem occurs.
Because the Page Setup dialog box is open and active, I cannot press the
'Stop Recording' button. If I close the dialog box that action is included
in the macro therefore defeating the purpose of the macro. I've tried
editing the macro, but can't seem to get that right either.

All suggestions welcome. Thanks!
 
J

Jay Freedman

RKEvans said:
Help. Through user error I managed to wipe out all of my macros this
mornings. I have been able to recreate most of them, but I am having
some trouble with what should probably be the simplest one and I
originally created it so long ago that I cannot remember how I did it.

All I want the marco to do is open the Page Setup dialog box. I am
recording the macro as a button on the tool bar and I am using the
following key strokes: Alt, File, Page Setup. This is where the
problem occurs. Because the Page Setup dialog box is open and active,
I cannot press the 'Stop Recording' button. If I close the dialog
box that action is included in the macro therefore defeating the
purpose of the macro. I've tried editing the macro, but can't seem
to get that right either.

All suggestions welcome. Thanks!

This will do it:

Sub PageSetupDialog
Dialogs(wdDialogFilePageSetup).Show
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
U

Ugnz

My question is, how do you find out what the dialog box is called. I've seen
this question twice now, for different dialog boxes, and I don't want to have
to ask every time I want to write a macro for a new dialog box.

I've tried, and unfortunately wild guessing doesn't do the trick :)

Thanks
 
J

Jay Freedman

There are several ways to approach this:

- In the VBA editor, click View > Object Browser (or the shortcut, F2). In the
search box (to the left of the binoculars icon), type wdDialog and press Enter.
This will give you a list of all the members of the WdWordDialog enumeration,
which you can scroll through, looking for a likely match. Or search on the term
that appears in the title bar of the dialog when you display it from the menu --
for example, searching on "setup" will find wdDialogFilePageSetup and
wdDialogFilePrintSetup.

- In the VBA help, look at the topic "Built-In Dialog Box Argument Lists".
Besides listing all the WdWordDialog values, this table also shows the names of
the arguments you can set or retrieve. Unfortunately, it doesn't tell you the
data types or meanings of the arguments. Read
http://www.word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htm for help with that job.

- Put together the name of the menu (in Word 2003 or earlier) and the menu item
that you would click to open the dialog, and stick "wdDialog" in front of it.
Then look for that name in either of the first two lists -- if you find it
there, you probably have the right name (try it!).
 

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