Categories: excel, excel-vba, vba

Run-time Error '1004' - Method 'Open' of object 'Workbooks' failed

7 answers

OK, so far I've uninstalled & re installed Office-2010 3 to 4 times, done hours of research for 3 days with no success. I started getting this error either from Vbscript or Excel VBA, performing the same command that has worked for months. I am not sure what I may have changed, I don't recall changing anything that could cause it but I nailed it down to the ReadOnly:=True parameter. I think something may be wrong with the registry... but re-installing should fix it right? It didn't...

Anyways, very simple command that I recorded on Excel 2010. This command WORKS FINE and the file opens:

Sub Macro1()      Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx" End Sub 

But when I add the ReadOnly:=True parameter, it does NOT WORK:

Sub Macro1()      Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx", ReadOnly:=True End Sub 

This is the returned error Run-time error '1004' Method 'Open' of object 'Workbooks' failed:

When I click Debug, the error is at the only line of code.

All answers to this question, which has the identifier 19965380

The best answer:

The file is corrupted. Resave it with another name and change the name in the function. Try that it works and after that rename the file as you want to call it.

It worked for me and I had a corrupted file. The read only shouldn't be a problem.

I have had the same issue with an Access file stored in a local OneDrive folder, referencing an Excel file stored in the same local OneDrive folder. The solution was to move all files into a "static" (i.e., not synchronized, not OneDrive) folder.

Thought that this specific case/application might help someone.

Putting an answer here for others like myself who have this issue and the normal solutions don't work.

Another potential cause of this is corrupted temporary files. I think it may only apply if the file you are trying to open is on a network drive or other remote host.

Anyway, try wiping your temp folder (as in the one you get to if you type %temp% into Windows Explorer) then restarting the computer.

If you are downloading the file from some external source (eg- email), just open the file directly from the email and then save the file. Try opening the file in macro ...hope it works...it worked for me....:)

I had a rogue excel process that was running in the background. When I killed it from the task manager the code worked. I hope this helps.

I realise this is late but if you want to open & repair a corrupted workbook automatically use:

Set oWB = Workbooks.Open(Filename:="C:\my\file\path.xlsx", CorruptLoad:=XlCorruptLoad.xlRepairFile) 

I know I'm answering late on this, but I resolved a similar issue (same error but running excel from a .Net app) by making sure VBA was installed correctly on the target machine.

Control Panel->Programs and Features->Uninstall a Program... find your Office install, Right-click and select "change" ->Add Remove Features->Office Shared Features->Visual Basic for Applications->Run From My Computer

This did it for me.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data