Dears,
I'm trying to update a code found on the web to list all files and subfolder in a folder.
The problem I'm having is that I do not want to list also the content of subfolders.
Example:
Folder C:\Test
Content
C:\Test\Test1.txt
C:\Test\Sub\Test2.txt
Output
C:\Test\Test1.txt or Test1.txt
C:\Test\Sub or Sub
Below the code I'm trying to update
Thank you,
D
I'm trying to update a code found on the web to list all files and subfolder in a folder.
The problem I'm having is that I do not want to list also the content of subfolders.
Example:
Folder C:\Test
Content
C:\Test\Test1.txt
C:\Test\Sub\Test2.txt
Output
C:\Test\Test1.txt or Test1.txt
C:\Test\Sub or Sub
Below the code I'm trying to update
VBA Code:
Sub ListAllFilesInAFolder()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim i As Integer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Test")
For Each oFile In oFolder.Files
Cells(i + 1, 1) = oFile.Name
i = i + 1
Next oFile
End Sub
Thank you,
D