View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.charting
Reinhard Reinhard is offline
external usenet poster
 
Posts: 2
Default Creating chart from vb.net

Thank you very much for your help!
Reinhard

"Ed Ferrero" wrote:

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