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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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