[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1570
  • Last Modified:

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

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?
1 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

mjfourAuthor Commented:
Awesome and Easy, thanx

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now