Store contents of combobox in Word file

Posted on 2007-08-06
Last Modified: 2013-12-26
I have a word document that has a combobox on it.  I am currently populating the combobox with multiple collumns from a ADSI query.  I would like to save the combobox contents within the word file so that I can send the word document to others without the need for any additional source files, database connections or anything (I want to programatically populate the combobox initially and then allow users to see the "cached" combobox contents).  

Ideally there'd by a programatic way to
1.  Take my existing contents of the combobox and store them in a hidden area or array in the document
2.  allow the document to be saved with the data
3.  Automatically repopulate the combobox with the stored information.

Question by:btree
    LVL 7

    Expert Comment

    Could you use something like this in the VBA of the Word Document?


    Private Sub Document_Open()
      Dim Counter As Long
      For Counter = 1 To 100
         Me.ComboBox1.AddItem ("TEST " & Format(Counter, "000"))
      Next Counter
    End Sub
    LVL 2

    Author Comment

    I am familiar with the .additem to populate the combobox, however once the combobox is populated I want to take the contents and store them in the word document so that I can then re-populate the combobox the next time the document is opened.  It is my understanding that a combobox's contents are not saved with the document and the combobox must be populated everytime the document is opened.
    LVL 10

    Accepted Solution

    What sort of data are you talking about?  If there's not too many items, you might consider writing them as custom properties (see File\Properties\Custom for the sort of thing I mean).  Just create each item as a property according to a unique naming scheme when you first load the combobox, then programatically pull them back out when you want to populate.
    LVL 10

    Expert Comment

    Or you could muck about with a range of hidden text (perhaps one line per combobox item), where you set the font property to Hidden.  This would be messier, and users who had their Word options set to see all non-printing characters would still see the hiden text.
    LVL 2

    Author Comment

    The type of data is contact information such as first name, last name, email address, mailing address.  There would be 5 - 100 names and addresses.  I realize I could link to an external file such as an excel sheet but I would like to be able to send this one word document only to those who need to use it.  Would Jaynee's method work for this?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
    This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now