如何用VBA遍历指定目录下的所有子文件夹和文件
1个回答
展开全部
Sub 文件夹内遍历法()
Dim arr, n&, i&, j&, s$, sh
Dim myPath$, myFile$
Dim cnn As Object, rs As Object, wb As Workbook
myPath = ThisWorkbook.Path & "\"
myFile = Dir(myPath & "*.xlsm")
n = CreateObject("Scripting.FileSystemObject").GetFolder(myPath).Files.Count - 1
ReDim arr(1 To 1000, 1 To n)
Do While myFile <> ""
If myFile <> ThisWorkbook.Name Then
Set wb = myFile.Sheets
End If
myFile = Dir
Loop
Range("A1").Resize(j, i) = arr '输出
End Sub
Dim arr, n&, i&, j&, s$, sh
Dim myPath$, myFile$
Dim cnn As Object, rs As Object, wb As Workbook
myPath = ThisWorkbook.Path & "\"
myFile = Dir(myPath & "*.xlsm")
n = CreateObject("Scripting.FileSystemObject").GetFolder(myPath).Files.Count - 1
ReDim arr(1 To 1000, 1 To n)
Do While myFile <> ""
If myFile <> ThisWorkbook.Name Then
Set wb = myFile.Sheets
End If
myFile = Dir
Loop
Range("A1").Resize(j, i) = arr '输出
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |