+ Reply to Thread
Results 1 to 4 of 4

Get file names from a directory

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2007
    Posts
    23

    Get file names from a directory

    I have a macro that contains a drop down box with a list of file names that are contained in a single directory. Currently, I store the file names in a separate sheet and have to manually enter a new filename if a new file is added. Is there a way I can code something to pull the names of the files in the directory?

  2. #2
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Sub getfiles()
    Dim mypath As String, myname As String
    mypath = "c:\data"
    myname = Dir(mypath & "\*.xls")
    Do While myname <> ""
    'show every file in a messagebox
    'or change to suit your needs
        MsgBox myname
        myname = Dir
    Loop
    End Sub
    Charlize

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, This adds the File names to a "Control Toobox", "Combobox":-
    'Combobox addItem
    Dim r As Integer, F As String, Directory As String
    Directory = "C:\documents and settings\test\desktop\excel\"
    r = 1
    F = Dir(Directory) ', 7)
    With ComboBox1
    Do While F <> ""
    .AddItem F
    F = Dir()
    Loop
    End With
    ComboBox1.ListIndex = 0
    MsgBox "complete"
    Regards Mick

  4. #4
    Registered User
    Join Date
    10-01-2007
    Posts
    23
    Thanks, combined a little bit of both and it worked great!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1