Excel \ OpenOffice Calc Dir函数不会迭代文件

时间:2014-01-30 07:38:19

标签: excel vba openoffice-calc dir

我的VBA代码只返回目录的第一个文件,而它应该返回至少3个文件,有没有人知道这里有什么线索?

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

1 个答案:

答案 0 :(得分:0)

试试这段代码(请注意,我在FileName = Dir循环的末尾添加了While):

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