Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

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

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:empfile_9928_131101.xlsx"
End Sub

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

Sub Macro1()
     Workbooks.Open Filename:="C:empfile_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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...