Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 4 of 4

Thread: Add files in directory to a listbox

  1. #1
    Join Date
    28th February 2005
    Posts
    72

    Add files in directory to a listbox

    hello,


    I want to show the files from a directory in a listbox by pressing a button.
    is there a short and understandable code for this??


    thanks for your help

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    28th January 2003
    Location
    Solihull - England
    Posts
    8,677

    Re: Files in directory

    What do you want to be able to do once you have them in your listbox ? The reason I ask is that if you want to be able to open them, it would be simpler to use the GetOpenFileName dialog box

    VB:
    chdir("C:\Will\") :application.GetOpenFilename 
    
    
    Will show the OpenFile dialog box, containing a list of all files in the directory C:\Will\
    Kind Regards, Will Riley

    Web Presence:
    Personal: Datasapien
    LinkedIn: Will Riley

  3. #3
    Join Date
    28th January 2003
    Location
    Solihull - England
    Posts
    8,677

    Re: Files in directory

    If you want to add the files to a listbox on a userform, places the following in a userform initialise event

    VB:
    Private Sub UserForm_Initialize() 
        Dim fileList() As String 
        Dim fName As String 
        Dim fPath As String 
        Dim I As Integer 
         'define the directory to be searched for files
        fPath = "C:\Will\" 
         
         'build a list of the files
        fName = Dir(fPath & "*.xls") 
        While fName <> "" 
             'add fName to the list
            I = I + 1 
            Redim Preserve fileList(1 To I) 
            fileList(I) = fName 
             'get next filename
            fName = Dir() 
        Wend 
         'see if any files were found
        If I = 0 Then 
            MsgBox "No files found" 
            Exit Sub 
        End If 
         'cycle through the list and add to listbox
        For I = 1 To UBound(fileList) 
            Me.ListBox1.AddItem fileList(I) 
        Next 
    End Sub 
    
    
    Kind Regards, Will Riley

    Web Presence:
    Personal: Datasapien
    LinkedIn: Will Riley

  4. #4
    Join Date
    28th February 2005
    Posts
    72

    Re: Add files in directory to a listbox

    that last one was good enough for me.

    thanx

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. All Image Files From Directory
    By DROM in forum EXCEL HELP
    Replies: 3
    Last Post: November 25th, 2006, 09:53
  2. List Of Files In A Directory
    By adaleh in forum EXCEL HELP
    Replies: 5
    Last Post: October 9th, 2006, 14:11
  3. Replies: 2
    Last Post: February 8th, 2006, 12:23
  4. Counting files in a directory
    By major-b in forum EXCEL HELP
    Replies: 1
    Last Post: March 1st, 2005, 19:06
  5. Listbox With File Names From Directory
    By Albert in forum EXCEL HELP
    Replies: 7
    Last Post: March 26th, 2003, 11:57

Bookmarks

Posting Permissions

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