문제

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