Home |
Search |
Today's Posts |
#1
|
|||
|
|||
How do I create a drop down list in word - in simple terms
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 |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
You may also want to look at the AutoTextList field.
http://www.mvps.org/word/FAQs/TblsFl...toTextList.htm -- Charles Kenyon Word New User FAQ & Web Directory: http://addbalance.com/word Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide See also the MVP FAQ: http://www.mvps.org/word which is awesome! --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom. "Jinny" wrote in message ... 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 |
#4
|
|||
|
|||
hi Jay - i just made a post with a similar question to Jinnys - that I think
you may have answered below - the only thing is - if I have 50 combo boxes is there a simple code that will run on opening and populate all the combo boxes? "Jay Freedman" wrote: 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 |
#5
|
|||
|
|||
Simple? I doubt it... but you'll have to tell us more about what you want to
do. - Do all the comboboxes need to have the same list of entries, or are they all different? - If they're different, where is the data coming from? Will it be hard-coded in the macro as it is in the one below, or taken from some other source? - Do you need to save the selections and restore them on reopening the document? As pointed out in another branch of this thread, you may want to look at the AutoTextList field (http://word.mvps.org/FAQs/TblsFldsFms/AutoTextList.htm) as a simpler alternative. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org DanG wrote: hi Jay - i just made a post with a similar question to Jinnys - that I think you may have answered below - the only thing is - if I have 50 combo boxes is there a simple code that will run on opening and populate all the combo boxes? "Jay Freedman" wrote: 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Please give us REVEAL CODES like WORD PERFECT not reveal codes in. | Microsoft Word Help | |||
Making Word do something that Wordperfect can do | New Users | |||
How do I get my default new document to always be our company let. | Microsoft Word Help | |||
Open with... does not include Word | Microsoft Word Help | |||
How to change merge forms from Word Perfect to Microsoft Word | Microsoft Word Help |