转载自品略图书馆 http://www.pinlue.com/article/2020/05/1214/5110507453707.html
经常用到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
VBA遍历文件夹下Excel文件

本文介绍了一个使用VBA编写的脚本,该脚本能够遍历指定文件夹下所有的Excel文件,并将文件名存储在数组中。通过这个脚本,用户可以轻松地获取到文件夹内所有Excel文件的数量,适用于需要批量处理Excel文件的场景。
1万+

被折叠的 条评论
为什么被折叠?



