Hey guys I am having difficulty with this VBA. I have gotten it to search for all excel files within a folder, but now I need it to be able to access excel files that are within folders from a parent directory. I have the following code:
Sub LoopThroughDirectory()
Dim MyFile As String
Dim erow
fpath = Worksheets(1).Range("B3").Value & "\"
MyFile = Dir(fpath)
Do While Len(MyFile) > 0
If MyFile = "zmaster.xlsm" Then
Exit Sub
End If
Debug.Print Now, MyFile
Workbooks.Open fpath & MyFile
Range("A2:D3").Copy
ActiveWorkbook.Close
erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Worksheets("sheet2").Paste Destination:=Worksheets("sheet2").Cells(erow, 1)
MyFile = Dir
Loop
fpath = Worksheets(1).Range("B4").Value & "\"
MyFile = Dir(fpath)
Do While Len(MyFile) > 0
If MyFile = "zmaster.xlsm" Then
Exit Sub
End If
Debug.Print Now, MyFile
Workbooks.Open fpath & MyFile
Range("A2:D3").Copy
ActiveWorkbook.Close
erow = Sheet2.Cells(Rows.Count, 7).End(xlUp).Offset(1, 0).Row
Worksheets("sheet2").Paste Destination:=Worksheets("sheet2").Cells(erow, 7)
MyFile = Dir
Loop
End Sub
I have it set up so that it pulls the directory name from a certain cell, which would be inputted by the operator, it works fine when I have all the spreadsheets within the same folder, but if there are folders within that folder with files I need it won't look for them.
Another problem I have is that when copying the data from the spreadsheets it does open, a pop-up comes up when copying larger amounts of data, is there any way to stop that pop-up from appearing?
Bookmarks