This is something that lots of people need to do in one form or another. I'll
give you my general approach, and then you should be ready to work out the
details for your specific case.
To see how my approach works, create a new document called Test1.
Afterwards, you can apply the techniques that I'll describe to your document,
but I suggest that you see how things work in my simple example before you
try to do anything in your document. Note that in Word 2007, you'll need to
save this document as a Word Macro-Enabled Document, close it, and re-open
it. Also, in Word 2007, whenever you open this document, you'll need to make
macros available.
For my example, in Test1, type "The color selected is " and create a
DocVariable field named Color immediately after this text. An easy way to do
this is to type DOCVARIABLE Color, block this text add press Cntrl+F9. Then
press Alt+F9 a few times to toggle Show Field Codes and verify that you have
a field code that looks like {DOCVARIABLE Color}. Save Test1.
The next step is to create a user form, that is, the dialog box that will
pop up when you open the document. With the new document (Test1) opened,
press Alt-F11 to open Microsoft Visual Basic. In Project Explorer, expand
Project(Test1), right-click Microsoft Word Object, point to Insert, and click
User Form. This will create a user form named UserForm1. For my simple
example, add a combobox and a button to UserForm1. Their default names will
be ComboBox1 and CommandButton1. Select CommandButton1, and in the Properties
Window, change the value of Caption to OK. The button should now look like an
OK button.
Now double-click the OK button. This should open the Test1 - UserForm1
(Code) window with the cursor inside the code for the CommandButton1_Click
event.
Add the following line in this event: Me.Hide
Now add code to initialize the combo box. To do this, in the left-hand
drop-down list, select UserForm1, and in the right-hand drop-down list,
select Initialize. Then add code to the UserForm_Initialize event that will
display three choices for a color. The code for the two events will be as
follows.
Private Sub CommandButton1_Click()
Me.Hide
End Sub
Private Sub UserForm_Initialize()
ComboBox1.List = Array("Red", "Green", "Blue")
ComboBox1.ListIndex = 0
End Sub
The final step is to create the command that will set everything in motion
when you open the document. In Project Explorer, under Project(Test1),
double-click ThisDocument. This should display the code for the Document_New
event, which we don't need. In the right-hand drop-down list, select Open.
This should display the code for the Document_Open event. Add code to display
UserForm1 when the document is opened and to set the doc variable to the
color selected in ComboBox1 when control is returned to this event after the
dialog box is closed as follows.
Private Sub Document_Open()
UserForm1.Show
Me.Variables("Color").Value = UserForm1.ComboBox1.Value
ActiveDocument.Fields.Update
End Sub
Finally, save everything in Microsoft Visual Studio, and then save and close
Test1.
Now, open Test1. A dialog box in which you can select a color should appear.
Select a color, and click OK.
If you see the name of the color that you selected in Test1, you should be
ready to do what you need to your document for your specific case.