I'm getting close to what I want but not quite there. I can get it to work if I'm just adding a ChartObject to the current sheet, but I want to create a new Chart sheet and can't seem to get the declarations and/or casting to come out right (even if I turn off Option Strict) so it leaves the Excel process running.
vb.net Code:
Dim xlApp As Excel.Application = Nothing Dim xlWorkBooks As Excel.Workbooks = Nothing Dim xlWorkBook As Excel.Workbook = Nothing Dim xlWorkSheet As Excel.Worksheet = Nothing Dim xlWorkSheets As Excel.Sheets = Nothing Dim xlRange1 As Excel.Range = Nothing Dim xlInterior As Excel.Interior = Nothing Dim xlColumns As Excel.Range = Nothing xlApp = New Excel.Application xlApp.DisplayAlerts = False xlWorkBooks = xlApp.Workbooks xlWorkBook = xlWorkBooks.Open(FileName) xlApp.Visible = False xlWorkSheets = xlWorkBook.Sheets xlWorkSheet = CType(xlWorkSheets(1), Excel.Worksheet) 'process the data for the chart into Sheet1 Dim xlChart As Excel.Chart = Nothing xlChart = CType(xlWorkBook.Charts.Add(After:=xlApp.ActiveSheet), Excel.Chart)
The last line is what causes me problems. I tried several different ways to declare the Charts collection (for example, xlCharts = CType(xlWorkBook.Charts, Excel.Charts), but it would eventually give me an error.
A minor complaint is that it is also not putting the Chart sheet after the ActiveSheet even though that is returning "Sheet1" as it should.This operation failed because the QueryInterface call on the COM component for the interface with IID '{0002086D-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002
So what am I missing?




Reply With Quote
