0

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
MPelletier
  • 16,256
  • 15
  • 86
  • 137
userX
  • 370
  • 3
  • 11
  • I cant accept answer for another 50 seconds... Rookie policy of StackoverFlow. PS: Do you know how to format a digit to 3-digits? For example 3 to 003 – userX Jan 30 '14 at 07:52

1 Answers1

0

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
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80