View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

Hi Jinny,

The code you have will load the items into the combobox. The problem
you have is that the code isn't running each time you reopen the
document. Saving the document when the items are loaded into the
combobox does *not* save the items in place -- the box has to be
reloaded every time.

To make this work, you need two more macros in the same template.
These macros must have the special names AutoNew() and AutoOpen(). The
first one runs automatically when someone uses File New to create a
document based on the template, and the second one runs each time one
of those documents is reopened. Each of the macros needs to call
TitleList:

Public Sub AutoNew()
TitleList
End Sub

Public Sub AutoOpen()
TitleList
End Sub

Another thing that may cause you grief is that TitleList contains the
line ".ListIndex = -1", which causes the combobox to start with a
blank display (nothing selected). I can guess that when you make an
entry, save and close, and reopen, you want the combobox to display
the same selection. In the current circumstances that won't happen.

To change this takes several steps. You have to save the selection so
it can be restored on reopening. These macros go in a regular module
(use Insert Module in the VBA editor):

Public Sub AutoNew()
TitleList
ThisDocument.ComboBox1.ListIndex = -1
End Sub

Public Sub AutoOpen()
On Error Resume Next
TitleList
ThisDocument.ComboBox1.ListIndex = _
ActiveDocument.Variables("TitleItem").Value
End Sub

Private Sub TitleList()
With ThisDocument.ComboBox1
.Clear
.AddItem "Mr"
.AddItem "Mrs"
.AddItem "Miss"
.AddItem "Unknown"
End With
End Sub

This macro goes in the ThisDocument module:

Private Sub ComboBox1_Change()
ActiveDocument.Variables("TitleItem").Value = _
ComboBox1.ListIndex
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Sun, 22 May 2005 18:15:01 -0700, "Jinny"
wrote:

Whilst I can appreciate some of the answers that are provided to similar
questions already posted, they are provided in such a technical way that they
are of little use to an everyday user. Please is there not a simple way to
explain how to create a drop down list within word for text options only. I
am able to create the list of choices in VB, but when I save and return to
the word document, the choices are not visible. I have attached a small sample
Private Sub TitleList()
With ComboBox1
.Clear
.AddItem "Mr"
.AddItem "Mrs"
.AddItem "Miss"
.AddItem "Unknown"
.ListIndex = -1
End With
End Sub