Power Query Course in Spanish
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: populating a list box or combobox with filenames

  1. #1
    New Member
    Join Date
    Apr 2002
    Location
    Jason in Boston MA
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    If anyone can help me with the creating the code to populate a listbox with all of the files in a given folder, so that a user can select a specific file. Also the number of files changes on a daily basis and the folder accesed can be any one of 3.

    THanks Jason

  2. #2
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-05 23:19, ecoscientist wrote:
    If anyone can help me with the creating the code to populate a listbox with all of the files in a given folder, so that a user can select a specific file. Also the number of files changes on a daily basis and the folder accesed can be any one of 3.

    THanks Jason
    Hi jason

    Here is general code to populate a Listbox
    with files......



    Dim Lb As MSForms.ListBox
    Dim F
    Dim x As Integer

    Set Lb = Me.ListBox1
    Lb.Clear

    F = Dir("C:Excelfiles*.XLS")
    If F = "" Then MsgBox "Directory doesn't exist!": GoTo Ex

    Application.ScreenUpdating = False

    x = 1
    On Error GoTo FileErr
    Do While Len(F) > 0
    Lb.AddItem F
    x = x + 1
    F = Dir()
    Loop

    GoTo Ex

    Exit Sub
    FileErr:
    MsgBox Err.Number & Chr(13) & _
    Err.Description, _
    vbMsgBoxHelpButton, _
    "File load Error", _
    Err.HelpFile, _
    Err.HelpContext

    Ex:
    Application.ScreenUpdating = True
    End Sub



    I suspect that your needsmay be a little diff
    If you can explain what it is you are doing you may not need to do this.....


    Kind Regards,
    Ivan F Moala From the City of Sails

  3. #3
    MrExcel MVP Aladin Akyurek's Avatar
    Join Date
    Feb 2002
    Location
    The Hague, NL
    Posts
    83,613
    Post Thanks / Like
    Mentioned
    33 Post(s)
    Tagged
    6 Thread(s)

    Default

    Ivan,

    Why not create the list of files with code, say in a sheet called, Admin and create a dynamic name range, say, FileList for the area where the VBA code creates it. FileList can then be used as source range in a ListBox or Combobox.

    Aladin

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-04-06 00:22, Aladin Akyurek wrote:
    Ivan,

    Why not create the list of files with code, say in a sheet called, Admin and create a dynamic name range, say, FileList for the area where the VBA code creates it. FileList can then be used as source range in a ListBox or Combobox.

    Aladin
    Aladin...yes you can do this...depends what
    he really wants to do...doing like this
    (not adding to sheet) just skips an extra step......
    Kind Regards,
    Ivan F Moala From the City of Sails

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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