MS Word Dropdown

Embed Size (px)

Citation preview

  • 8/12/2019 MS Word Dropdown

    1/2

    Support for Office 2003 has endedMicrosoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security

    options.Learn what this means for you and how to stay protected.

    Article ID: 161598 - View products that this article applies to.

    This article was previously published under Q161598For a Microsoft Excel for Mac version of this article, see 185388 (http://support.microsoft.com/kb/185388/ ) .

    This article describes methods of populating a ComboBox or ListBox control.

    Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the impliedwarranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is beingdemon strated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particularprocedure, but they will not m odif y these examples to provide added functionality or construct procedures to meet your specific requirements.

    For mor e information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS (http://suppo rt.microsoft.com/default.aspx?scid=fh;en -us;cntactms)

    You can use a control, such as a combo box or a list box, on a user form. In Microsoft Excel, you can use these controls in the worksheet. The methods forpopulating the controls are similar. The examples in this article use controls on a user form.

    Method 1: How to Link a Combo Box or List Box to Cells on an Excel Worksheet

    1. Create a new workbook in Microsoft Excel. On Sheet1, type the following:

    2. Press ALT+F11 to start the Microso ft Excel Visual Basic Editor.3. On the Insert menu, click UserForm .4. Create a ComboBox control and a ListBox control on the user form.5. If the Properties window is not visible, click Properties Window on the View menu.6. Click the ComboBox and scroll to RowSource in the Properties window .

    The window is divided into two sections. The left section contains the name of the proper ty for the control. The right section contains the value of theproperty. Click in the right section of RowSource and type " sheet1!a1:a4 " (without the quotation marks).

    7. Click the ListBox and scroll to RowSource in the Properties window. Click in the right section of RowSource and type " sheet1!b1:b4 " (without the quotationmarks).

    NOTE : If you omit the sheet reference, the ComboBox and ListBox controls are populated with the data from the cells from the worksheet that is activewhen you run the user form. To ensure that the data from the same worksheet is always used to populate the user form, include the sheet reference asshown in the examples. To populate the user form with data from the active sheet, do not include the sheet reference in the RowSource. When you do this,

    the macro uses data from the active sheet to populate the user form.8. Run the user form by clicking Run and then clicking Run Sub/UserForm .

    One, Two, Three, and Four appear in the ComboBox control; and Red, Green, Yellow, and Blue appear in the ListBox control.

    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:

    How to add data to a ComboBox control or aListBox control in Excel or Word

    SUMMARY

    MORE INFORMATION

    A1: One B1: Red A2: Two B2: Green A3: Three B3: Yellow A4: Four B4: Blue

    http://support.microsoft.com/kb/185388http://-/?-http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactmshttp://support.microsoft.com/kb/185388http://-/?-http://office.microsoft.com/en-us/help/support-is-ending-for-office-2003-HA103306332.aspx
  • 8/12/2019 MS Word Dropdown

    2/2

    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.

    For more information about user forms, click the Index tab in Microsoft Visual Basic Help, type the following text:UserForm Object

    and then double-click the selected text to go to the "UserForm Object" topic.

    Article ID: 161598 - Last Review: August 19, 2010 - Revision: 7.0

    APPLIES TOMicrosoft Excel 2002 Standard Ed itionMicrosoft Word 2002Microsoft Excel 2000 Standard Ed itionMicrosoft Word 2000Microsoft Excel 97 Standard Edi tionMicrosoft Word 97 Standard EditionMicrosoft Word 2010Microsoft Office Word 2007Microsoft Office Excel 2003Microsoft Excel 2010Microsoft Office Excel 2007Microsoft Office Word 2003

    Keywords: kbcontrol kbdtacode kbhowto kbprogramming KB161598

    ListBox1.List = Array("One", "Two", "Three", "Four") ComboBox1.List = Array("Red", "Green", "Yellow", "Blue")

    REFERENCES

    Properties