Hi All,
Any help would be gratefully received on this.
I have a macro which loops through various worksheets that are contained in a directory and copies them into a master workbook.
The problem is that yesterday my importloop macro was working perfectly but now I am receiving Run-time error '1004':
'name_of_the_first_file.xlsx' could not be found.....
The vba is managing to read the filename perfectly so it must be finding it but something is clearly not working. Does anybody know why this is?
Here is the code for my macro.
Thank you
Any help would be gratefully received on this.
I have a macro which loops through various worksheets that are contained in a directory and copies them into a master workbook.
The problem is that yesterday my importloop macro was working perfectly but now I am receiving Run-time error '1004':
'name_of_the_first_file.xlsx' could not be found.....
The vba is managing to read the filename perfectly so it must be finding it but something is clearly not working. Does anybody know why this is?
Here is the code for my macro.
Code:
Sub ImportLoop()
Dim MyObj As Object, MySource As Object, file As Variant
If MsgBox("Are you sure that you want to import sheets?", vbYesNo, "Confirmation... ") = vbNo Then Exit Sub
ChDir _
"X:\Import files directory"
SourceDir = "X:\Import files directory"
file = Dir(SourceDir)
While (file <> "")
Workbooks.Open Filename:=file, UpdateLinks:=0
Sheets.Copy Before:=Workbooks("Master Workbook.xlsm").Sheets(4)
Windows(file).Activate
ActiveWindow.Close False
file = Dir
Wend
End Sub
Thank you