遍历文件夹下所有文件并输出文件名

​Sub OpenAndClose()

Dim MyFile As String

Dim Arr(1000) As String

Dim count As Integer

MyFile = Dir("C:\Users\mikowoo\Desktop\EPSreport\result\" & "*.xlsx")

count = count + 1

Arr(count) = MyFile

Do While MyFile <> ""

MyFile = Dir

If MyFile = "" Then

Exit Do

End If

count = count + 1

Arr(count) = MyFile

Loop

For i = 1 To count

'Workbooks.Open Filename:="C:\Users\mikowoo\Desktop\EPSreport\result\"&Arr(i)

'Cells(1,1)="alex bn lee'

Debug.Print Arr(i)

'ActiveWorkbook.Close savechanges=True '关闭打开的文件

Next

Debug.Print s

End Sub

(0)

相关推荐