Question

My VBA-Code only returns the first file of the the directory while it should return at least 3 files, does anyone have a clue whats going on here?

FolderName = Environ("UserProfile") + "\"
FilePath = FolderName & "Invoice." & Format(Date,"yyyy.mm.dd") & "-" & "*" & ".ods"

count = 1
FileName = Dir(FilePath)

While (FileName <> "" And count < 5)
    MsgBox "FileName = " + FileName
    count = count + 1
Wend
Était-ce utile?

La solution

Try this code (note that I added FileName = Dir in the end of the While loop):

FolderName = Environ("UserProfile") + "\"
FilePath = FolderName & "Invoice." & Format(Date,"yyyy.mm.dd") & "-" & "*" & ".ods"

count = 1
FileName = Dir(FilePath)

While (FileName <> "" And count < 5)
    MsgBox "FileName = " + FileName
    count = count + 1
    FileName = Dir
Wend
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top