View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.charting
Ed Ferrero[_2_] Ed Ferrero[_2_] is offline
external usenet poster
 
Posts: 99
Default Creating chart from vb.net

Hi Reinhard,

Excel charts need to have at least one data series before you can set the
title, try adding the line of code below.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ExcelApp As New Microsoft.Office.Interop.Excel.Application
Dim MyWorkbook As Microsoft.Office.Interop.Excel.Workbook
Dim MyChart As Microsoft.Office.Interop.Excel.ChartObject
Dim ChartSheet As Microsoft.Office.Interop.Excel.Worksheet

Try
ExcelApp.Visible = True
MyWorkbook = ExcelApp.Workbooks.Open("C:\MyWorkbook.xls")
ChartSheet = MyWorkbook.Sheets(1)
MyChart = ChartSheet.ChartObjects.Add(Left:=50, Width:=800,
Top:=50, Height:=500)
MyChart.Chart.ChartType = XlChartType.xl3DBarClustered


MyChart.Chart.SeriesCollection.Add
Source:=MyWorkbook.Worksheets(1).Range("A1:A2")

MyChart.Chart.HasTitle = True 'this line causes the error

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub


Ed Ferrero
www.edferrero.com