Excel Automation Workbooks.Open fails: "Unable to get the Open Property ..."
I'm working with a web application that performs some Excel automation (I know - not a preferred solution).
I am using Excel 2007 as my development platform but the target server uses Excel 2003. After experiencing a lot of headaches with the Excel 12 interop trying to be loaded on the target server even though I expressly selected Excel 11 during development, I have resorted to using late binding rather than early binding.
This has allowed me to get as far so as to instantiate Excel (and I can see the Excel process start in task manager on the target server).
However I am unable to invoke the Open method of the late-bound Workbooks object. It throws this error at me:
"Unable to get the Open property of the Workbooks class"
I have been experimenting w开发者_开发知识库ith a few different things and have tried the following:
In all three cases, the Excel automation succeeds. It's only when I deploy the ASP.NET application that this error crops up. In a very simplified form, the code resembles:
Dim xlApp As Object 'Excel.Application
Dim xlBook As Object ' Excel.Workbook
xlApp = CreateObject("Excel.Application") 'New Excel.Application
xlBook = xlApp.Workbooks.Open("somefile.xls", , True, , , , , , , , , , , , False)
Does anyone have any ideas as to what might be happening? I checked the user that the Excel process starts as, and it is the same user that I successfully ran the Windows Forms .NET application as successfully. I had already opened Excel as this user to clear all the initial setup stuff.
I'm getting this same problem and I found some sites saying the following: Try going to file - options - add-ins - select diabled add-ins in the manage dropdown - click go - and enable anything in there.
It didn't work for me but it might for you.
Better a late answer then never...
When developing a VBscript make sure you handle the error that prevent closing your Excel Book correctly.
I got the same error as you, but I found out that when a error occurs within my logic, the interpreter doesn't close the Excel Book making it unavailable to further process.
Dim XLWkbk 'Excel workbook
Set xlApp = CreateObject("excel.application")
On Error Resume Next
Set XLWkbk = xlApp.Workbooks.Open("somefile.xlsm")
If Err.Number <> 0 Then ' Catch your error
WScript.Echo "Error while opening: " & Err.Number & " " & Err.Description
XLWkbk.Close False ' Close your workbook.
xlApp.Quit ' Quit the excel program.
WScript.Quit
Err.Clear
End If
WScript.Echo "Opened"
Be sure to handle the error with all function that operates on a file (SaveAs, Close, etc...)
Omitting the last argument fixed it for me.
xlBook = xlApp.Workbooks.Open("somefile.xls", , True, , , , , , , , , , , , )
精彩评论