Consulting

Results 1 to 5 of 5

Thread: Solved: Load a combobox with data from a .txt

  1. #1
    VBAX Regular
    Joined
    Sep 2005
    Location
    Rome
    Posts
    20
    Location

    Solved: Load a combobox with data from a .txt

    Hi all,
    I don't suppose anyone knows whether a combobox could "Load" (using AddItem) the data from a .txt file.
    The combobox is residing in a PowerPoint file. I'd like it to "upload" the data from a .txt file that I create on a weekly basis.
    Any ideas are appreciated.

    Thanks,

    GSD

  2. #2
    VBAX Regular
    Joined
    Sep 2004
    Posts
    65
    Location
    hi GSD

    I have an application (in Word) that loads a box from an INI file. The structure will be different but in my app I read the values into an array and then additem thus;

    The way I see it you will need to pre-process your text file into some combobox friendly form.

    [VBA]
    For iSection = 1 To UBound(arrNumbers)
    lstNumbers.AddItem UCase(arrNumbers(iSection))
    Next iSection
    [/VBA]

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Provided your text file doesn't require any manipulation, you could try something like the following:

    [VBA]
    Dim strTextFile As String
    Dim strLine As String


    strTextFile = "C:\Test\MyTextFile.txt"

    Open strTextFile For Input As #1

    Do Until EOF(1)
    Input #2, strLine

    lstNumbers.AddItem strLine
    Loop

    [/VBA]

  4. #4
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    Quote Originally Posted by geekgirlau
    Provided your text file doesn't require any manipulation, you could try something like the following:

    [VBA]
    Dim strTextFile As String
    Dim strLine As String


    strTextFile = "C:\Test\MyTextFile.txt"

    Open strTextFile For Input As #1

    Do Until EOF(1)
    Input #2, strLine

    lstNumbers.AddItem strLine
    Loop

    [/VBA]
    Nice code. Learn a point here.

  5. #5
    VBAX Regular
    Joined
    Sep 2005
    Location
    Rome
    Posts
    20
    Location
    Hi all and thanks.
    I did have to change the
    Input #2, strLine
    to
    Input #1, strLine

    But it's up and working!
    Another mystery solved. Thanks again to everyone that contributed.
    GSD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •