Microsoft Office Tutorials and References
In Depth Information
Filling a Word Combo Box with Data from Excel
4. To see and change the text box names in the Visual Basic Editor (VBE),
click on a text box, and then look at the Name information in the
Properties window (it will usually be the first entry listed). Type the
correct name in the box if changes need to be made.
5. Insert a bookmark named txtStartBody in the location where the user
should start typing once the macro has finished.
Deciding not to use a bookmark means that the macro will simply skip
selecting the location if a bookmark isn't present.
6. Feel free to change the form to fit various requirements. Deleting and
adding labels and text boxes will not affect the macro tool. Just be
careful not to delete the buttons.
7. In the Visual Basic Editor (VBE), go to Tools | References and activate
the checkbox next to one of the Microsoft ActiveX Data Object library
entries. (As the code is very simple, the version of ADO is not
significant. The sample document references the oldest version, 2.0.)
8. ADO connections are application-specific. If an Access table is used
instead of an Excel workbook, a different connection ('conn' in the
procedure 'FillStateList') is needed. Find the code for an Access
connection in the tool in Mail Merge: Creating a One-to-Many List on
page 205. For other database types, see the information on ADO OLE
DB connections at . If the data
is in a Word table, see the code for generating an MS Graph chart in the
Mail Merge: Merging with a Chart entry on page 215 .
9. Set the .Visible property of the text box being replaced in the UserForm
with the combo box to False. The text box is still needed on the
UserForm so that Word can process the data to and from the
corresponding bookmark.
10. Insert a combo box from the Forms toolbox. Position and size it. Give it
a name; in the example, it is named 'cboState' and the corresponding
text box is named 'txtState'.
11. In the procedure 'GetUserInput', substitute the names that were given
to the combo boxes and text boxes in the lines following comments
starting with !Substitute (three places).
12. In the procedure 'FillStateList', enter the information for the workbook
in the four lines below the comment 'The relevant information for the
Excel file.
Search JabSto ::

Custom Search