where to insert code in dropdown box?

W

William Millspaugh

I have 2 templates, one of them has some dropdowns with a yes or no
selection. What I need to know is where does this code go... I need this
dropdown to automatically bring up another document if the answer is
"yes".......

If ActiveDocument.FormFields("DropDown1").result = "Yes" Then
Documents.Add ("TemplateName.dot")
End If

I know it needs to relate to the dropdown box in the doc. Could someone
explain...

Thanks alot. Bill
 
J

Jay Freedman

Hi Bill,

General instructions are at http://www.gmayor.com/installing_macro.htm, but
you need a bit more than that.

In the template that contains the dropdown, open the VBA editor and type
this line:

Sub ExitDropdown1()

When you press Enter at the end of the line, Word will automatically supply
the line

End Sub

Between those two lines, paste the three lines you showed.

Also make sure the name "DropDown1" matches the bookmark name shown in the
dropdown's Properties dialog, and that "TemplateName.dot" matches the name
of the template you want to base the new document on. Change them to match
if necessary. Save the template and close the VBA editor.

Back in the template, open the dropdown's Properties dialog. Pull down the
Exit list and select ExitDropdown1. This sets the connection so that the
macro runs when the cursor leaves the dropdown.

Save the template again, and create a new document on it to test the
dropdown.

One other minor bit: The equality test in the macro is case-sensitive. In
other words, the choice in the dropdown that makes the new document appear
*must* be "Yes" and not "YES" or "yes". There's a way to change the macro's
behavior if necessary, but it's easier to just make sure the dropdown has
the right case.

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

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