I'm looping through a folder using :
Dim file As Variant
file = Dir(myFolder)
While (file <> "" )
mySub file '<= this sub use Dir() hundreds of times !!!
file = Dir()
Wend
mySub
breaks the Dir loop
since it give me the next file of a different folder.
Is there a easy way to work around that limitation ? If not, how would you proceed ?
Current solution
I'm currently using running a first loop storing the filename in an Array
, then running a second loop processing mySub from the Array
:
Dim file As Variant
file = Dir(myFolder)
Dim myArray() as String
Redim myArray(0)
While (file <> "" )
Redim Preserve myArray(Ubound(myArray) + 1)
myArray(Ubound(myArray)) = file
file = Dir()
Wend
Dim n as Integer
For n = 1 to Ubound(myArray)
mySub myArray(n)
Next