Embed pulldown menu in a document

K

Kathryn Pundt

I would like to have a pulldown menu (hereinafter "menu") inside my document,
but not to include just a couple of words - like the button feature offers.
I would like the menu to show several options. After selecting an option, a
macro would insert the selected paragraph of text.

Thank you.
 
K

Kathryn Pundt

I have seen those instructions and they are not quite what I need. I don't
want to have a box that has options of one or two words. I want a box that
has some keywords that when selected, it runs a macro that inserts a file
into the current open file.
 
J

Jay Freedman

The items in an AutoTextList field aren't necessarily limited to just a couple
of words, but they are limited to 32 characters... so OK.

Another possibility is a dropdown form field with an exit macro that inserts
different files depending on the selection in the dropdown. The main drawback
here is that the document -- or at least the section containing the dropdown --
must be "protected for forms" to make it work. (See the tutorial at
http://www.computorcompanion.com/LPMArticle.asp?ID=22.) When you do that, a
number of other features are disabled and require workarounds; for example, see
http://www.word.mvps.org/FAQs/MacrosVBA/SpellcheckProtectDoc.htm. A second
drawback is that entries in the dropdown are limited to 50 characters each, and
no more than 25 entries.

The most flexible alternative is a userform
(http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm) containing a list
box and OK and Cancel buttons. The code in the OK button's click procedure can
find out which item in the list was selected, and insert the corresponding file
in the document at a pre-arranged bookmark.

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

Kathryn Pundt

Okay. I will check out the links. But, going down a different path, if I
created a toolbar with pulldown menus and embedded into the template, that
might give me the same results as I inquired below. Is it possible to create
a toolbar, then attach it to a template, that when opened, the toolbar pops
up on your screen?
 
K

Kathryn Pundt

Jay, Thank you for you help. I appreciate it.
Going back to my original question, it seems like it would be an easy thing
to do - to insert a pull-down button into a template that when pulled down
several options popped up. When one option is selected, it would trigger a
small macro to insert a file at that point in the document. Could you
please, in layman's terms, explain why it cannot be done? I would like to
understand the way Word thinks. :)
 
J

Jay Freedman

You don't exactly "attach" a toolbar to a template, you save the toolbar in the
template. First open the template (or a document based on it), then in the Tools
Customize > Toolbars > New dialog open the "Make toolbar available to"
dropdown and choose that template instead of Normal.dot. The toolbar will then
be displayed in any document based on that template.
 
J

Jay Freedman

I'm not sure it's possible to explain the way Word thinks, in layman's terms or
any other terms! ;-)

The dropdown form field, besides requiring protection for forms and having a
limited capacity, doesn't fire a macro or any other kind of event when the user
changes the choice in the list. Nothing happens until the user exits the field
by tabbing or clicking, and then only if you've designated an exit macro.

Technically, there is a way to do what you ask, but I'm reluctant to recommend
it.

Besides the dropdown form field, there is another type of dropdown you can put
into the body of a document -- a combo box ActiveX control that you can get from
the Control Toolbox (one of the toolbars on the View > Toolbars menu). This kind
of control is described at
<http://msdn2.microsoft.com/en-us/library/aa140269(office.10).aspx>. If, after
reading the section about "Appropriateness for the Task", you still want to use
one, you need these hints:

- By default, users can type anything into the edit box at the top of the combo
box control. To force them to choose only from the presented list of items, you
must click the Properties button on the Control Toolbox and set the combo box's
MatchRequired property to True.

- The code that inserts the necessary file could be placed in the combo box's
Change procedure. To get there, while the combo box is selected, click the View
Code button on the Control Toolbox. Across the top of the VBA editing window,
you should see the combo box's name on the left and "Change" on the right; in
the window you should see an empty procedure with a name like
ComboBox1_Change().

- The problem with using the Change procedure is that if the user repeatedly
changes the combo box selection, the Change procedure will fire each time,
putting multiple files into the document. You would need to arrange that each
insertion first removes any previous insertion, possibly by overwriting the
range of a bookmark. (To make that work you need to read
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.)

An alternative is to use the LostFocus procedure, which executes only when the
user clicks or tabs away (same as the exit macro of a dropdown form field). Of
course, since the user could go into and out of the combo box repeatedly, you
still need to provide a way to remove the preceding choice of text to prevent
them from piling up.
 

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