經(jīng)常用到excel,以下是遍歷當前文件夾下的excel表。
Sub bl()
Dim myPath As String, myFile As String
Dim i As Integer
Dim Arr() As String
i = 0
myPath = ThisWorkbook.Path & "\*.xls*"
myFile = Dir(myPath)
If myFile <> ThisWorkbook.Name Then '如果不是本文件,取出放入數(shù)組(2019年2月28日修改)
ReDim Preserve Ar(i) '不清空數(shù)組
Ar(i) = myFile
i = i + 1
End If
Do While myFile <> ""
myFile = Dir
If myFile = "" Then
Exit Do
End If
ReDim Preserve Ar(i) '不清空數(shù)組
Ar(i) = myFile
i = i + 1
Loop
MsgBox "共" & i & "個excel文件"
End sub