avoiding error 1004 method open of object workbooks failed

khawarameer

Board Regular
Joined
Jun 2, 2009
Messages
152
I am trying to merge some excel 2003 work books in one excel 2010 workbook with VBA and experiencing following error
"Error 1004 method open of object workbooks failed"

Following code is used.

Sub GetSheets()
Path = "C:\Users\bal-admin\Desktop\Transfer Register\"
Dim number As Integer
number = 1
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
ActiveSheet.Name = number
Sheet.Copy After:=ThisWorkbook.Sheets(1)
number = number + 1
Next Sheet
Workbooks(Filename).Close savechanges:=False
Filename = Dir()
Loop
End Sub

Any solution please
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Are you sure that the file you are trying to open is a valid Excel file? It must exist because Dir has returned its name. Can you open it manually?
 
Upvote 0
is it possible that there is a macro run when the book is opened? Are you sure it is the open giving the error and not the close?

Looking at your code I see a couple things that are going to cause problems.
 
Upvote 0
try looking at the "CorruptLoad" parameter. maybe CorruptLoad:=xlRepairFile will let it open.
 
Upvote 0

Forum statistics

Threads
1,222,180
Messages
6,164,423
Members
451,894
Latest member
480BOY

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