-----Original Message-----
Kelly,
There are 2 ways -- semi-slick (using a protected form), and
very slick, using a custom dialog ("userform").
[1] Semi-Slick Method:
First, store the following macro in the template:
Sub UpdateMyFields
ActiveDocument.Fields.Update
End Sub
Now isolate the first mention of the company name so that
no other variable text is in the same paragraph. Add a
continuous section break just after it -- and also just
before it if it's not the first thing in the file. From
the user's POV this design will work best if the company
name is prominent and early.)
(Display the Forms toolbar if it's not showing -- click
View-> Toolbars-> Forms.) In place of the first mention
of the company name, add a DropDown formfield using the
Forms toolbar (icon looks like a set of little rectangles
or, as one pupil insists, a very squared-off coat of arms.
Double-click the formfield you just inserted and in the
Options dialog that appears, add the 4 company names to
the DropDown Item List box. Note the displayed bookmark
name (probably DropDown1) to be assigned to the formfield
you're creating. Optionally (but recommended), change it
to something more descriptive, say, CompanyName. In the
Run Macro On Exit box, select the name of the macro you
just stored. Click OK.
Now click Tools> Protect Document. In the dialog that
appears, click Sections. In the next window, clear the
checkboxes for all sections except the one your dropdown
formfield is in. Click OK and OK again.
(Note that this 'protecting' has nothing to do with making
the file safe, unopenable, sanitary, child-resistant, etc.
In Wordspeak, "protecting a section for forms" just means
everything in it except formfields will be frozen, i.e.,
unchangable by the user, essentially duplicating a paper
form where you can fill in blanks, checkboxes, etc., but
not change their labels.)
In the other places in the doc that are to contain the
company name, enter regular fields like this:
{ CompanyName }
Note that you must enter the braces using CTRL+F9 and NOT
with the '{' and '}' keys. [Terminology note: These are
'regular' fields, as opposed to 'formfields' like the one
you built earlier.] Now save the template and close it.
When the user launches a new doc based on your template,
he/she can click the dropdown arrow that'll appear next
to the company name and choose one of the 4 options.
Pressing TAB to exit the formfield takes him/her to the
next section and runs the macro that updates the other
fields so that they all show the selected company name.
[2] Very Slick Method:
Build a small userform, called by the AutoNew macro in
the template so it'll appear whenever a new document is
created from it. Have it contain a 'ComboBox' control
(function is similar to the dropdown formfield above)
and have the button that dismisses the form insert the
value the user chooses from the ComboBox at locations
in the document (template) at which you have inserted
bookmarks. In this method, the user would see a custom
dialog (just like a Word dialog, such as Font, Print,
etc.) in front of the document in which he/she can
choose the company name. You can also design the
userform to prompt for other things to be inserted
into the document, potentially alleviating mountains
of tedium.
If this all sounds vague, it's because explaining how
to build a userform is beyond the scope of a simple
newsgroup reply. Building a userform is indeed more
work than building a protected form, but it will (1)
make your users ecstatic, and (2) reveal dozens of
new possibilities for saving time and nerves.
Protected forms have numerous limitations that tend
to frustrate anyone who gets deeply involved with
using them. And since you know some Excel VBA, what
you'd need to learn in Word VBA wouldn't likely faze
you much. (Both programs can have userforms and the
code specific to the design and structure userforms
is 100% identical.)
If this sounds even remotely useful, see the comments
at
http://www.speakeasy.org/~mtangard/userforms.html
and then try the brief tutorial on the MVP site at
http://www.mvps.org/word/FAQs/Userforms/CreateAUserForm.ht m
--
Mark Tangard <
[email protected]>, Microsoft Word MVP
Please reply ONLY to the newsgroup, not by private mail.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters
Hi all, I am using the Office 200 package and am fairly
new to VB but have a bit of experience with Excel VB.
Anyway what I would like to do is...
I have a template that currently a number of users have
access to. If I can build a slick little macro that allows
the user to select one of four company names. Then
everywhere in the document that needs that name it would
automatically replace with the name selected.
That way I can use the same credit application template
for each of four different financial institutions. As we
have already come up with a format that each institution
will agree to use we just have to make it simple to change
the name throughout the form.
I suspect there is some already existing ways to do this
but I am unfamiliar with WORD.
Thanks
Kelly
.
Hey Mark, I finally had a chance to try out your