ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel 2000 open using C# error - Unable to cast COM object of type (https://www.excelbanter.com/excel-programming/409751-excel-2000-open-using-c-error-unable-cast-com-object-type.html)

George

Excel 2000 open using C# error - Unable to cast COM object of type
 
Hi,

I am using Excel 2000 with C# in VS 2008. I added the excel 9.0 reference
from COM tab under Reference. I am using VS 2008 and win forms.



The code snippet is given below :



Excel.Application appExcel = new Excel.Application();

appExcel.DisplayAlerts = false;


Excel.Workbook wbkExcel = appExcel.Workbooks.Open("C:\\emp.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing); //<--Error here

Excel.Worksheet wksExcel = (Excel.Worksheet)wbkExcel.Sheets[0];

wksExcel.Activate();



wbkExcel.Close(false, Type.Missing, Type.Missing);

appExcel.Quit();



System.Runtime.InteropServices.Marshal.ReleaseComO bject(wksExcel);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(wbkExcel);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(appExcel);

wksExcel = null;

wbkExcel = null;

appExcel = null;

GC.Collect();



The error is :

"Unable to cast COM object of type
'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type
'Microsoft.Office.Interop.Excel._Application'. This operation failed because
the QueryInterface call on the COM component for the interface with IID
'{000208D5-0000-0000-C000-000000000046}' failed due to the following error:
Library not registered. (Exception from HRESULT: 0x8002801D
(TYPE_E_LIBNOTREGISTERED))."



Any help is appreciated.



Thanks.
george



Rashmi Pandey

microsoft.public.excel.programming
 
I am getting the same error in my application. Have you come across any work around for this error? Please suggest...


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com