Solved

Word RowSource syntax

Posted on 2014-07-24
4
1,391 Views
Last Modified: 2014-07-25
This should be straight forward, but haven't been able to figure it out.  I have created a Word template that has a form that allows the user to make entries to populate the template.

There are free form text boxes and radio buttons.  I would like to add a simple list box offering a choice between several states.

I cannot for the life of me figure out the RowSource syntax.  I would think it would be something simple like ="Choice1, Choice2, Choice3,...." but this is not working.

I am going to use the value selected in the list box to insert a block of text that will vary depending on the selection.  I have done this successfully based on radio button choices and would like to do the same now with a listbox.
0
Comment
Question by:reportingdude
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40217483
I'm not sure that Word supports bound controls. However, to be clear, are you using ActiveX controls? If so, are they on the document (not recommended), or on a UserForm?
0
 

Author Comment

by:reportingdude
ID: 40217562
Its a UserForm through VBA. I am not sure if the controls are ActiveX controls.  When I hit the toolbar button it has option button, list box, combo box, etc available.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40218702
The controls on a UserForm are all ActiveX controls. They can also be put on documents, but it isn't recommended.

I have researched this a bit more. As far as I can establish, the RowSource property only works if the data is on a Worksheet in the current Workbook. This confines it to Excel.

This Microsoft article http://support.microsoft.com/kb/161598 is headed "How to add data to a ComboBox control or a ListBox control in Excel or Word". The first uses the RowSource and shows how to set it to a worksheet range. The second method uses VBA to set the list to an array, which would, of course work in Word, or any other UserForm host.

A third method is to use AddItem successively
ListBox1.AddItem "Choice1"
ListBox1.AddItem "Choice2"

Open in new window

0
 

Author Closing Comment

by:reportingdude
ID: 40220158
Excellent.  Not sure how I missed finding that link, here are the directions from the link you provided that did the trick:

Methdod 2: How to Use a Visual Basic Macro to Populate a Combo Box or List Box
1.Open a Microsoft Office Application such as Microsoft Excel or Word.
2.Press ALT+F11 to start the Visual Basic Editor.
3.On the Insert menu, click UserForm.
4.Create a ComboBox and a ListBox control on the user form.
5.Right-click the user form and click View Code. The Code window for the user form appears. Click Initialize in the Procedure list (on the right side).

The first and last lines of the subroutine are automatically entered, and the insertion point is automatically placed between these two lines.
6.Type the following code:
      ListBox1.List = Array("One", "Two", "Three", "Four")
      ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")
                                    This code should appear between the lines "Sub UserForm_Initialize()" and "End Sub".
7.On the Run menu, click Run Sub/UserForm to run the user form.
One, Two, Three, and Four appear in the ListBox control; and Red, Green, Yellow, and Blue appear in the ComboBox control.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question