+ Reply to Thread
Results 1 to 3 of 3

Thread: Copy Files Names in Eplorer using VBA Macro in Excel

  1. #1
    Registered User
    Join Date
    05-09-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Copy Files Names in Eplorer using VBA Macro in Excel

    I need some help writting a marco that will copy all file names inside a designated folder (I.e. windows explorer on my c: drive) and then paste the results into my open spread sheet. Ideally, I would like to have my spread sheet open, then run the macro, and then the file names will appear. One file name per cell. Thank you for any help!!

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    6,566

    Re: Copy Files Names in Eplorer using VBA Macro in Excel

    Hi,

    One way:

    Sub ListFileNames()
        Dim fso, ofileItem, oSource, stDirectory As String, lCounter As Long
        
        stDirectory = "C:\" 'your folder - change as appropriate
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set oSource = fso.GetFolder(stDirectory)
    
        For Each ofileItem In oSource.Files
            lCounter = lCounter + 1
            Sheets("sheet1").Cells(lCounter, 1) = ofileItem.Name
        Next ofileItem
    
        Set fso = Nothing
    End Sub
    Regards
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

  3. #3
    Registered User
    Join Date
    05-09-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Copy Files Names in Eplorer using VBA Macro in Excel

    That worked great! Thank you Richard for the quick reply!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0