I am running an older ASP.NET web application on a new computer that has Vista 64 with IIS7 and Office 2007 installed. The application has some code in an asp.net page that access the Excel.Application objects and this code is now failing on this new system.
I created a small test application using the ASP.NET Web application and dropped in enough of the code to duplicate the problem. (Code shown below)
At first the new sample web app's properties were set to use the "Use Visual Studio Development Server" and with that server the excel code works fine. When I switch to "Use IIS Web server" the code begain to fail.
At first the virutal directory was using the DefaulAppPool, and with that setting the following line was failing with a {"Cannot create ActiveX component."} error.
loExcelApp = CreateObject("Excel.Application")
Then I changed the application pool for the WebApplication virtual directory to be the "Classic .NET AppPool" which is configured for .NET Framework Version v2.0 and Enable 32-Bit Applications set to True. It also has the Identity set to a local admin account.
Now it gets through most of the excel code but ultimately fails on the .SaveAs line...
oWorkbook.SaveAs("C:\MyFile1.xls")
SaveAs method of Workbook class failed
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: SaveAs method of Workbook class failed
I have also tried using early binding for excel instead of the late binding and also tried compiling the applicatin as x86, but these changes made no difference with the error.
So at this point I am trying to figure out if this is a problem with IIS 7, vista 64 or Office 2007.
Any insite into how to resolve this would be appreciated.
-- Steven
Dim oExcelApp As Object = Nothing
Dim oWorkbooks As Object = Nothing
Dim oWorkbook As Object = Nothing
Dim oSheet As Object = NothingoExcelApp = CreateObject("Excel.Application")
' Create an excel workbooks object
oWorkbooks = oExcelApp.Workbooks
' Create an excel workbook
oWorkbook = oWorkbooks.add
' Initialize the work sheet.
oExcelApp.DisplayAlerts =
False
oSheet = oExcelApp.ActiveSheet()
oSheet.Name =
"MyTestSheet"
oSheet.Cells(1, 1).Value =
"Some Data"
' Save the file, this is where it fails.
oWorkbook.SaveAs(
"C:\MyFile1.xls")