Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2
Default Creating chart from vb.net

Hello,

i want to add a chart to a Excel-Sheet with vb.net. (VS 2005). This is
possible, but on setting the HasTitle property i get an exception: "Exception
from HRESULT: 0x800A03EC".
If anybody could help me I would be very thankfull.

I have installed Microsoft Excel 2003 (11.8105.8107) SP2.
I added a reference to the "Microsoft Excel 11.0 Object Library", Version
1.5 from the COM tab. This creates following references to my project:
-Excel, Name: Microsoft.Office.Interop.Excel, Version: 1.5.0.0 (Description:
Microsoft Excel 11.0 Object Library)
- Microsoft.Office.Core, Name: Office, Version: 2.3.0.0 (Description:
Microsoft Office 11.0 Object Library)

Here is the code to reproduce the probleme:
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.HasTitle = True 'this line causes the error

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

Thank you in advance for your help

Reinhard

  #2   Report Post  
Posted to microsoft.public.excel.charting
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

  #3   Report Post  
Posted to microsoft.public.excel.charting
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
NEED HELP CREATING A CHART mj Charts and Charting in Excel 2 October 9th 07 01:15 AM
Creating a Pie Chart Linzzy016 Charts and Charting in Excel 1 December 3rd 06 07:27 PM
Creating a Chart SJT Excel Discussion (Misc queries) 1 July 11th 06 11:21 AM
creating a pie chart blue Charts and Charting in Excel 1 April 20th 06 09:04 AM
creating a chart Devin Charts and Charting in Excel 0 April 28th 05 12:50 AM


All times are GMT +1. The time now is 08:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"