返回满足条件的第一个文件名:myFileName = Dir(ThisWorkbook.Path & “\利润表_*.xls”)
返回所有文件名myFileName = Dir(ThisWorkbook.Path & “\”)
Sub cyclefiles()
Dim MyFile As String
Dim s As String
Dim count As Integer
MyFile = Dir(ThisWorkbook.Path & "\" & "*.xlsx")
'读入文件夹中的第一个.xlsx文件
count = count + 1 '记录文件的个数
s = s & count & "、" & MyFile
Do While MyFile <> ""
MyFile = Dir '第二次读入的时候不用写参数
If MyFile = "" Then
Exit Do '当MyFile为空的时候就说明已经遍历完了,这时退出Do,否则还要运行一遍
End If
count = count + 1
If count Mod 2 <> 1 Then
s = s & vbTab & count & "、" & MyFile
Else
s = s & vbCrLf & count & "、" & MyFile
End If
Loop
Debug.Print s
End Sub