Hi PV
This works in Excel 2010...don't have 2013
Option Explicit
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Sheets("Sheet1")
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("C:\") '<-----Change this line to suit
With ws
.Cells.Clear
.Cells(1, 1).Value = "The files found in " & objFolder & " are:"
End With
'Loop through the Files collection
FindFilesInAllFolders objFolder, True '<-----Change this line to True to list all subdirectories
' For Each objFile In objFolder.Files
' ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
' Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
ws.Columns.AutoFit
End Sub
'http://www.excelforum.com/excel-programming/764746-exclude-files-from-getopenfilename-based-on-file-name.html#post2474970
'Written: March 24, 2010
'Author: Leith Ross
'Summary: List all files in a single folder or all files in the subfolders of the parent
' folder on the ActiveSheet. The file name, date and time it was last modified
' are listed in column "A:B" starting at row 1.
'Adapted by jaslake 03/29/2011 and 04/21/2013
Sub FindFilesInAllFolders(ByVal SourceFolderName As String, ByVal IncludeSubfolders As Boolean)
Dim FSO As Object
Dim SourceFolder As Object
Dim SubFolder As Object
Dim FileItem As Object
Dim LR As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder(SourceFolderName)
For Each FileItem In SourceFolder.Files
With Sheets("Sheet1")
LR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Cells(LR, "A") = SourceFolder '& FileItem.Name
.Cells(LR, "B") = FileItem.Name
End With
Next FileItem
If IncludeSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
FindFilesInAllFolders SubFolder.Path, True
Next SubFolder
End If
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub
Bookmarks