返回满足条件的第一个文件名:myFileName = Dir(ThisWorkbook.Path & “\利润表_*.xls”)
    返回所有文件名myFileName = Dir(ThisWorkbook.Path & “\”)

    1. Sub cyclefiles()
    2. Dim MyFile As String
    3. Dim s As String
    4. Dim count As Integer
    5. MyFile = Dir(ThisWorkbook.Path & "\" & "*.xlsx")
    6. '读入文件夹中的第一个.xlsx文件
    7. count = count + 1 '记录文件的个数
    8. s = s & count & "" & MyFile
    9. Do While MyFile <> ""
    10. MyFile = Dir '第二次读入的时候不用写参数
    11. If MyFile = "" Then
    12. Exit Do '当MyFile为空的时候就说明已经遍历完了,这时退出Do,否则还要运行一遍
    13. End If
    14. count = count + 1
    15. If count Mod 2 <> 1 Then
    16. s = s & vbTab & count & "" & MyFile
    17. Else
    18. s = s & vbCrLf & count & "" & MyFile
    19. End If
    20. Loop
    21. Debug.Print s
    22. End Sub