TroyBarnes17
New Member
- Joined
- Jun 13, 2021
- Messages
- 12
- Office Version
- 365
- Platform
- Windows
Hi folks,
I have a few files in separate subfolders in a given folder and I am trying to perform an operation on all these files. This operation creates a new excel file, which needs to be in the .xls format as this is the one required by another programme for further analysis.
My issue is that once the loop begins, the operation is performed first on the file I want it to happen on, then on the file that's created as a results, and on and on.
Is there a way to get around this please?
I have a few files in separate subfolders in a given folder and I am trying to perform an operation on all these files. This operation creates a new excel file, which needs to be in the .xls format as this is the one required by another programme for further analysis.
My issue is that once the loop begins, the operation is performed first on the file I want it to happen on, then on the file that's created as a results, and on and on.
Is there a way to get around this please?
VBA Code:
Option Explicit
Sub ListFiles()
Application.screenupdating = False
ActiveSheet.Cells.Clear
'Call GetFiles("H:\Pet\Test\") 'end string with path separator ( \ )
End Sub
Private Sub GetFiles(ByVal path As String)
Dim FSO As Object, Fldr As Object, subF As Object, File As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Fldr = FSO.GetFolder(path)
For Each subF In Fldr.SubFolders
GetFiles (subF.path)
Next subF
For Each File In Fldr.Files
If LCase(Right(File.path, 4)) = ".xls" Then
'do something here
End If
Next File
Set FSO = Nothing
Set Fldr = Nothing
Set subF = Nothing
Set File = Nothing
End Sub