سؤال

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
هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top