Originally Posted by
zGod
but when it should go to the next one, the excel application closes
Hello,
your logic on paper is correct but not according to how VBA works as your second Dir cancels the previous !
So first follow Alan's answer above.
If for some obscure reason you wanna stay on VBA side that needs to create a recursive procedure.
If it's under Windows only and on a SSD drive
- or if you don't mind that may run six times slower than Dir on a mechanical hard drive -
an easier way is to use the Windows ActiveX FileSystemObject like
this thread
(Even both Dir & FSO can be combined in your case.)
If for MAC or with a mechanical hard drive the recursive procedure must use Dir VBA function, I'll share another sample link
Edit : maybe that no needs any recursive procedure if there is only a single level of subfolders in the master '2022' folder like
[
]\2022\Folder1
[
]\2022\Folder2
so not multiple sub levels like
[
]\2022\Folder1
[
]\2022\Folder1\Folder2
[
]\2022\Folder1\Folder3
[
]\2022\Folder1\Folder3\Folder4
[
]\2022\Folder5
[
]\2022\Folder5\Folder6
So if for some reason you wanna stay on VBA side is it a single sub level folders or multiple ?
Bookmarks