I am getting a run time error 1004. Can anyone help me with it? Consider me a noob at excel

AmanBesara

New Member
Joined
May 20, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Sub GetSheets()

' Write in the specific path where the file is saved in the path


Path = "D:jjjjj\Report 2019-20\"

Filename = Dir(Path & "*.xls")

Do While Filename <> ""

Workbooks.Open Filename:=Path & Filename, ReadOnly:=True

For Each Sheet In ActiveWorkbook.Sheets

Sheet.Copy After:=ThisWorkbook.Sheets(1)

Next Sheet

Workbooks(Filename).Close

Filename = Dir()

Loop

End Sub


This is the following code. I am basically trying to copy multiple excel files in one excel file. My error "Sheet.Copy After:=ThisWorkbook.Sheets(1)" . Can anyone help me debug it?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Are there any hidden sheets in the workbook that you're copying from?
 
Upvote 0
Is this a typo
Path = "D:jjjjj\Report 2019-20\"

should it be
Path = "D:\jjjjj\Report 2019-20\"
 
Upvote 0
Is this a typo
Path = "D:jjjjj\Report 2019-20\"

should it be
Path = "D:\jjjjj\Report 2019-20\"
Yes I have coded as this one
"D:\jjjjj\Report 2019-20\"

When I debug the error is in this line
Sheet.Copy After:=ThisWorkbook.Sheets(1)

I am unable to figure out
 
Upvote 0
What happens if you change Sheet to ws

Change it in the lines above and below as well. I believe that Sheet is a reserved keyword so it could be conflicting.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top