P
Prasun
Code:
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
oWB = oXL.Workbooks.Open("C:\data.xls") '---> Exception thrown here
'Dim ThisWorkbook As Excel.Workbook
Dim ThisWorksheet As Excel.Worksheet
ThisWorksheet = oWB.ActiveSheet
Dim charts As Excel.ChartObjects = _
CType(ThisWorksheet.ChartObjects(), Excel.ChartObjects)
' Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
Dim chartObj As Excel.ChartObject = charts.Add(100, 300, 500, 300)
Dim chart As Excel.Chart = chartObj.Chart
' Gets the cells that define the bounds of the data to be charted.
Dim chartRange As Excel.Range = ThisWorksheet.Range("A2", "B8")
chart.SetSourceData(chartRange)
chart.ChartType = Excel.XlChartType.xlXYScatter
Dim series As Excel.Series
Dim seriesCollection As Excel.SeriesCollection = _
CType(chart.SeriesCollection(), Excel.SeriesCollection)
series = seriesCollection.Item(seriesCollection.Count)
End Sub
I have the following exception thrown in the line shown above.
An unhandled exception of type 'System.NullReferenceException' occurred in
ChartDisplay.exe
Additional information: Object reference not set to an instance of an
object.
does anyone know what is wrong
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
oWB = oXL.Workbooks.Open("C:\data.xls") '---> Exception thrown here
'Dim ThisWorkbook As Excel.Workbook
Dim ThisWorksheet As Excel.Worksheet
ThisWorksheet = oWB.ActiveSheet
Dim charts As Excel.ChartObjects = _
CType(ThisWorksheet.ChartObjects(), Excel.ChartObjects)
' Adds a chart at x = 100, y = 300, 500 points wide and 300 tall.
Dim chartObj As Excel.ChartObject = charts.Add(100, 300, 500, 300)
Dim chart As Excel.Chart = chartObj.Chart
' Gets the cells that define the bounds of the data to be charted.
Dim chartRange As Excel.Range = ThisWorksheet.Range("A2", "B8")
chart.SetSourceData(chartRange)
chart.ChartType = Excel.XlChartType.xlXYScatter
Dim series As Excel.Series
Dim seriesCollection As Excel.SeriesCollection = _
CType(chart.SeriesCollection(), Excel.SeriesCollection)
series = seriesCollection.Item(seriesCollection.Count)
End Sub
I have the following exception thrown in the line shown above.
An unhandled exception of type 'System.NullReferenceException' occurred in
ChartDisplay.exe
Additional information: Object reference not set to an instance of an
object.
does anyone know what is wrong