The loop through all subfolders interrupts at not forseeable positions. No error message is thrown by VBA. The file being treated at the moment the code halts is different from time to time.
The files to be opened are raw, non-ascii files. Excel can convert them into csv files for further batch processing. I tried both of the following loops with the same result: 1. Loop Through All Subfolders Using VBA 2. Cycle through sub-folders and files in a user-specified root directory
Sub LoopFolders()
Dim FileSystem As Object
Dim HostFolder As String
HostFolder = "c:\abc\Donnees_de_production\"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Application.ScreenUpdating = False ' Deactivate Screenupdating
DoFolder FileSystem.GetFolder(HostFolder)
Application.ScreenUpdating = True
End Sub
Sub DoFolder(Folder)
Dim SubFolder As Object
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
Dim File As Object
For Each File In Folder.Files
' Operate on each file
Workbooks.Open FileName:=File.Path
' MsgBox File.Path & ".csv"
ActiveWorkbook.SaveAs FileName:=File.Path & ".csv", FileFormat:=xlCSV
ActiveWorkbook.Close
Next
End Sub
I have about 6500 files to convert to csv. The execution stops after around 1200. I have no idea why.
I highly appreciate any help or ideas! Thank you.