UserForm VBA - pulldown menu - Word2003

L

Laura J.

Hello.

I've created a template for proposals with a user form on the cover page. In
one corner, we'll always be putting in the logo for the agency to which we
are submitting the proposal. Is there a way to build in a pulldown menu in
the user form where the user can select which agency and the logo for that
agency appears? I have the logos we need - just have to figure out how to
use a pulldown menu to do this.

Thanks!

Laura
 
J

Jay Freedman

Hello.

I've created a template for proposals with a user form on the cover page. In
one corner, we'll always be putting in the logo for the agency to which we
are submitting the proposal. Is there a way to build in a pulldown menu in
the user form where the user can select which agency and the logo for that
agency appears? I have the logos we need - just have to figure out how to
use a pulldown menu to do this.

Thanks!

Laura

See http://www.word.mvps.org/FAQs/TblsFldsFms/AutoTextList.htm.

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

Todd

Sorry to appear stupid but Im looking for the same information. The article
you reference to Jay shows how to add this option to the document - but how
about adding it to a userform?

Thanks,
Todd
 
J

Jay Freedman

Hi Todd,

It isn't you that should worry about looking stupid. I overlooked the
userform aspect. (Strictly speaking, a form in a document isn't what
Microsoft calls a userform -- that term means a custom dialog box
created in the VBA editor. What you have is a "protected form" or what
Microsoft misleadingly calls an "online form".)

Unfortunately, an AutoTextList field doesn't work in a protected form.
The following works, though it's a bit clunky.

Add the logo pictures as AutoText entries in the template, with names
corresponding to the agencies/offices/etc. At the point where you want
the logo to appear in the form, insert a dropdown form field. In the
dropdown's Properties dialog, load the names of the AutoText entries
as the choices. Set the bookmark name in that dialog to "Logo"
(without the quotes).

In the VBA editor, insert this macro (see
http://www.gmayor.com/installing_macro.htm if you need instructions)
in a module within the template:

Sub exitLogo()
Dim LogoDropDown As Word.FormField
Dim ATname As String

With ActiveDocument
Set LogoDropDown = .FormFields("Logo")
ATname = LogoDropDown.DropDown.ListEntries( _
LogoDropDown.DropDown.Value).Name

If .ProtectionType <> wdNoProtection Then
.Unprotect
End If

.AttachedTemplate.AutoTextEntries(ATname).Insert _
Where:=LogoDropDown.Range, RichText:=True

.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub

Now go back to the dropdown's Properties dialog, open the "Run macro
on exit" box, and select exitLogo from the list.

Finally, protect the template and save it.

When you make a new document based on the template, you can open the
dropdown and select the desired agency name. When you tab or click out
of the dropdown, the macro will run and insert the corresponding logo
in place of the dropdown. The dropdown will no longer exist, so it
can't be changed again by this mechanism.

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

Todd

Sorry Jay - i think I am still after something different. I do want to
actually use a UserForm - your instructions are to place an autotext drop
down box in the document itself.

My scenario is to have one template for our team to use to standardize
letters. I have setup the userform in VBA to obtain all the personal details
of the recipient, but would like to do two more things. I would like to use
the case in point to select the appropriate signature block from whoever is
sending the letter. Also, I want to have four options as to the content of
the letter. (either use and optionbutton etc).

It is very confusing with the terminology as VBa and word both call what I
am doing a userform - but alot of the forum here uses that expression for
things handled within front end of word, and not back end.
 
D

Doug Robbins - Word MVP

You could use a two column combobox, with the sender's name displayed in the
first column and the corresponding path\filename of the signature to be
inserted in the second column, then have code in the command button that
inserts the "picture" of the selected item in the combobox.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jay Freedman

You're right, there's so much confusion in the newsgroups over
"forms", "userforms", and similar terms that it's hard to know what
the questions are about. Laura's original post was almost certainly
about a protected form in the body of the document. I finally get the
point that yours is about a VBA-based UserForm.

For the signature selection, I'll mostly agree with Doug Robbins that
a good mechanism is a 2-column combo box on the userform. I don't
think he mentioned that only the first column should be visible, but
the second column is still accessible to the code behind the userform
(usually the Click procedure for the OK button). The content of the
second column could be the path\filename of an external graphic file,
or it could be the name of an autotext entry in the template.

For the content options, you could use either option buttons or a
combobox. Again, the code behind the userform can look at the selected
value and use it to choose either an external file or an autotext
entry to insert into the document.

If all the active parts of the template are in the userform, it
probably isn't necessary to make the document itself protected. If you
want to protect it anyway, to lock it down so the user can't make
unauthorized changes, then you'll need the Unprotect and Protect code
from the macro I showed before.

By the way, there's a whole separate newsgroup devoted to userforms
(microsoft.public.word.vba.userforms, or
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?query=userforms
on the web).

--
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