经常用到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 '如果不是本文件,取出放入数组(2019年2月28日修改)
ReDim Preserve Ar(i) '不清空数组
Ar(i) = myFile
i = i + 1
End If
Do While myFile <> ""
myFile = Dir
If myFile = "" Then
Exit Do
End If
ReDim Preserve Ar(i) '不清空数组
Ar(i) = myFile
i = i + 1
Loop
MsgBox "共" & i & "个excel文件"
End sub