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