MS Word -

  • Thread starter Thread starter Laura
  • Start date Start date
L

Laura

Is it possible to select a title from the Drop Down Form
Field Options, and when you select one of the titles, the
form changes in certain sections while leaving some of the
information static? For example, could it change out
certain tables?
 
No, you need to write your own macros at this level of complexity. Happy to
help with the details if you get stuck, though.
 
Hi Laura

The approach I'd take is to store the variable parts of your document as
AutoText entries. For this to work they need to be saved to your template and
not Normal.dot. An AutoText entry can contain almost text,tables, graphics etc,
so they very flexible and they retain formatting. AutoText entries have names so
that you can easily locate the one you want. If you've not used autotext before
read Words online help.

In your document add a bookmark at each location where you want to swap out the
text. This is so that you can programmatically locate the point where the
various AutoText entries should go. You then need to assign OnExit macros to the
DropDown FormFields you want to use to insert the various AutoText entries into
your document.

The OnExit macro will use the selected value of the DropDown FormField to select
an AutoText entry that will be used to update the document.

Here are a few snippets of code to get you on your way:

Public Sub AAOnExit()
Dim strOptionSelected As String
Dim strAutoTextName As String

' Get the text of the selected DropDown FormField
strOptionSelected = Selection.FormFields(1).Result

' Choose as AutoText entry based on the selected option
' The entries in this list must correspond to the options in your
' DropDown FormField
Select Case strOptionSelected
Case "BlueText"
strAutoTextName = "Blue"
Case "RedText"
strAutoTextName = "Red"
Case "GreenText"
strAutoTextName = "Green"
Case Else
' You only get here if you selected something in your
' list that in not in the case statement
Exit Sub
End Select

' Now update the text at the selected bookmark
Application.ScreenUpdating = False
ActiveDocument.Unprotect
InsertAutoText strAutoTextName, "BM1"
ActiveDocument.Protect wdAllowOnlyFormFields, True
Application.ScreenUpdating = True
End Sub

Public Sub InsertAutoText(ByVal strAutoTextName As String, _
ByVal strBookmarkName As String)
Dim tplAttached As Word.Template
Dim rngLocation As Word.Range

' Insert specified autotext at the bookmarked location
' and then recreate the bookmark
Set tplAttached = ActiveDocument.AttachedTemplate
Set rngLocation = ActiveDocument.Bookmarks(strBookmarkName).Range
Set rngLocation =
tplAttached.AutoTextEntries(strAutoTextName).Insert(rngLocation, True)
ActiveDocument.Bookmarks.Add strBookmarkName, rngLocation
End Sub


I attached the above macro ("AAOnExit") as the OnExit macro of a DropDown
FormField, the FormField contained 3 entries: "RedText", "BlueText" and
"GreenText". I also added a bookmark to my template named "BM1". I added 3
AutoText entries to the template called "Red", "Blue" and "Green".

When you run the above code the text at the bookmark "BM1" will change depending
upon what you selected in your DropDown FormField.

The second macro "InsertAutoText" is the procedure that automatically updates
the bookmark using the specified autotext entry, as used in the statement:
InsertAutoText strAutoTextName, "BM1"

HTH + Cheers - Peter
 

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

Back
Top