How can I populate a VBA userform combo box values from a text or excel file?

Posted on 2009-02-14
Last Modified: 2012-06-21
I how someone can give me an easy solution. I am building a Word 2007 tempate and want to use a VBA userform to get data to populate into the form. My queation is I have a combo box where the values can be updated from time to time and I would like to keep all the default values in a text or excel file. How can I populate the combo box each time from the the text file?
Question by:mjfour
    LVL 76

    Accepted Solution

    I think that this will do what you want.
    Private Sub UserForm_Initialize()
        Dim f As Integer
        Dim strText As String
        f = FreeFile
        Open "C:\MyFolder\MyFile.txt" For Input As #f
        Do Until EOF(f)
            Line Input #f, strText
            Me.ComboBox1.AddItem strText
        Close #f
    End Sub

    Open in new window


    Author Closing Comment

    Awesome and Easy, thanx

    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

    If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
    The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
    This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
    In a previous video Micro Tutorial here at Experts Exchange (, I explained how to get a free, one-month trial of Office …

    737 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

    21 Experts available now in Live!

    Get 1:1 Help Now