+ Reply to Thread
Results 1 to 2 of 2

List files in a folder using FSO

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    List files in a folder using FSO

    The code below lists files in a folder.
    The first Sub uses a Browse Window dialogue to get the folder path. This one works.
    The second Sub just has the the folder path in the code. But it doesn't work. Is there a reason for this?


    Sub Test_1()
        Dim BrowseWindow As FileDialog
        Dim FSO As Object, SourceFolder As Object, SubFolder As Object
        Dim FileItem As Object
        Dim ThePath As String
        
        Set BrowseWindow = Application.FileDialog(msoFileDialogFolderPicker)
        If BrowseWindow.Show = -1 Then
            ThePath = BrowseWindow.SelectedItems(1)
        End If
        
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set SourceFolder = FSO.GetFolder(ThePath)
    
        For Each FileItem In SourceFolder.Files
            Debug.Print "File found"
        Next FileItem
    
        Set FileItem = Nothing: Set SourceFolder = Nothing: Set FSO = Nothing
    End Sub
    
    
    Sub Test_2()
        Dim FSO As Object, SourceFolder As Object, SubFolder As Object
        Dim FileItem As Object
        Dim ThePath As String
        
        ThePath = "C:\Test"
        
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set SourceFolder = FSO.GetFolder(ThePath)
    
        For Each FileItem In SourceFolder.Files
            Debug.Print "File found"
        Next FileItem
    
        Set FileItem = Nothing: Set SourceFolder = Nothing: Set FSO = Nothing
    End Sub

  2. #2
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: List files in a folder using FSO

    Apologies, it does work, please ignore.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. List of Files in Folder and sub folder
    By ayyappan80 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2020, 01:39 PM
  2. Replies: 5
    Last Post: 12-11-2019, 04:37 AM
  3. [SOLVED] Trouble Updating a list of Files if a file no longer exists in the Folder/Sub Folder Dir.
    By jrtraylor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-26-2019, 02:03 AM
  4. Copy Files from One Folder to Another Folder based on a List In Excel
    By civram1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-21-2019, 06:34 AM
  5. [SOLVED] Macro to list and open .xlsm files in folder and sub-folder
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-24-2019, 07:35 PM
  6. macros to list all files in folder THEN get info from files?
    By jonyorker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2015, 03:11 AM
  7. Noob 4 Help - Macro to LIST ALL FILES IN FOLDER and then IMPORT ALL LISTED FILES
    By StlSmiln in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-25-2012, 04:02 AM

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.6.0 RC 1