I am looping through files in one directory, it all works fine but it gets strange when I pass the file to another function in the module. It skips the first file retrieved in the loop!
Let's say the first loop run for example file
is "File1"
but once it hits copyFile (file)
then it passes "File2"
to the function, which also exists, for some reason it increments the loop automatically on calling the copyFile
function.
Dim file As Variant
file = Dir("PATH TO MY DIRECTORY")
Do While Len(file) > 0
Debug.Print file 'Here the right name is printed
file = Dir 'file here is also correct, at the beginning of the loop it shows File1
copyFile (file) 'Here suddenly the next file is sent to the copyFile
Loop
I have tried defining a string, storing file
in there and then pass it to copyFile(stringFile)
but the same happens.