所有子文件夹的循环在不可预见的位置中断。 VBA不会引发任何错误消息。代码暂停时正在处理的文件有时会有所不同。
要打开的文件是原始的非ASCII文件。 Excel可以将它们转换为csv文件,以进行进一步的批处理。 我尝试了以下两个循环,结果相同: 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
我大约有6500个文件可以转换为csv。执行大约在1200点左右停止。我不知道为什么。
我非常感谢您的任何帮助或想法! 谢谢。