opening MS Excel spreadsheet
-
I'm experiencing a problem w/ my application written in VB.Net. My application is suppose to open Excel, but when I try to create an object using CreateObject function it throws an exception, Specified cast is not valid. If I declare the xlApp as Excel.ApplicationClass it works, but a get the same problem, Specified cast is not valid, on the next line, xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook). I'm using Excel 2000 ver 9.02 and the OS is XP professional. I decided to load the latest version InteropServices, but I'm not using Office 2002. Even though it's loaded into the system the properties for the Excel COM object is pointing to the old version of Excel 2000. Any help would be appreciated. A sample of the code is as follows: Imports System.Runtime.InteropServices Imports Excel Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
-
I'm experiencing a problem w/ my application written in VB.Net. My application is suppose to open Excel, but when I try to create an object using CreateObject function it throws an exception, Specified cast is not valid. If I declare the xlApp as Excel.ApplicationClass it works, but a get the same problem, Specified cast is not valid, on the next line, xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook). I'm using Excel 2000 ver 9.02 and the OS is XP professional. I decided to load the latest version InteropServices, but I'm not using Office 2002. Even though it's loaded into the system the properties for the Excel COM object is pointing to the old version of Excel 2000. Any help would be appreciated. A sample of the code is as follows: Imports System.Runtime.InteropServices Imports Excel Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
I'm assuming you also went into Projects-->Add References-->COM-->Microsoft Excel X.X Object Library (where X.X = your version of Excel). Also, I have had some odd problems with interops. Unless I used the full domain names, they wouldn't work.
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Still coaxing software out of the can after all these years... -
I'm assuming you also went into Projects-->Add References-->COM-->Microsoft Excel X.X Object Library (where X.X = your version of Excel). Also, I have had some odd problems with interops. Unless I used the full domain names, they wouldn't work.
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Still coaxing software out of the can after all these years...