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

0
Reinhard (2)
12/13/2007 11:00:00 AM
excel.charting 18370 articles. 0 followers. Follow

2 Replies
748 Views

Similar Articles

[PageSpeed] 22

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 

0
ed5690 (69)
12/13/2007 11:30:44 AM
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 
> 
0
Reinhard (2)
12/13/2007 1:13:01 PM
Reply:

Similar Artilces:

Mailbox not created in Exchange when new Active Directory account created
Hello there, First off, I appologize if this question has been asked before. Prior to last week, whenever a new AD account was created along with a correpsonding Exchange mailbox, everything would work fine. However now things are not working normally and I am at a loss. Symptoms include: 1. When new AD account created, the email address and X.400 information is not pushed to the new account according to the Recipent Policy. 2. If we create the new AD account directly from the Exchange server console, the account inherits the recipient policy information however the new account never sho...

Make dynamic charts more dynamic
Hello all, I have a dynamic chart where I show the last 13 values in a spreadsheet column. I also implemented a slider bar so that I can go back and have a look at the previous values if I want. However, if I now daily update the column of data through an automated process and the chart shifts along dynamically, how do I also update the format controls of the slider bar using VBA automatically, that is, how do I adjust the maximum value of the format control as soon as a new value is added to the spreadsheet? Hope someone can help, thanks you. Milos. Hi, Depending on which type of s...

Widen Chart Columns
I'm using a stacked column format. I want to show data for about 3 weeks (1 week in each column). Everything looks fine, except the column seems very narrow. How do I change the width of the column on the chart? Thanks Hi, Double click column and adjust the GapWidth property on the series option tab. Also check the categroy axis is not being plotted as true dates as this will leave big gaps between non consectutive dates. Right click chart and choose Chart Options. On Axis tab set x axis to Category. Cheers Andy RichN wrote: > I'm using a stacked column format. I want...

How do I create Alpha-Numeric Numbering in Word 07? IE: Word_1.0
I need to create a numbering system that includes both Alpha and Numeric characters. Any ideas? If you are referring to static text, it's the same as in previous versions: just type it into the "Number format" box (of the appropriate dialog box). If you have created single-level numbering without attaching it to a paragraph style, place the insertion point in the numbered list. On the Home tab, click the arrow to the right of the Numbering button, and then click Define New Number Format. If you have created single-level numbering and attached it to a paragraph ...

chart with dynamic x axis
Is it possible to setup a chart of a time series so that the period charted can be defined by user inputs? For example, I have a chart o sales for the entire year. There is an input for 'month to review'. Even though I have sales for 12 months, if the user inputs 3 into thi field, I'd like the chart only to plot months 1-3. Any help i appreciated -- nam ----------------------------------------------------------------------- name's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3411 View this thread: http://www.excelforum.com/showthread.php?threadid...

Ignore N/A values with an area chart
I know that excel will ignore a value of #N/A on a line chart, but with an area chart, the result plots a value of zero, making the area look like a bunch of spikes. Is there a way to ignore that value and essentially connect the two available points to give the chart a continuous area? What you can do is interpolate between the adjacent values. There is no value that will make an area chart not dive to zero. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ SPeterson wrote: > I know that excel ...

3D area charts?
I'm interested in plotting X, Y, and Z axes to compare three properties of various products. As far as I can tell, Excel can't produce an area graph of this sort of data. I've found one website that shows how to do a mock- up 3D scatter plot based on three axes, but nothing that truly uses all three ... Anyone have suggestions? Excel cannot render a 3D scatter chart, in which X, Y, and Z are all continuous numerical variables. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ Epimetreus...

Rules
Hello, I am assigning rules to sort my email and need to know whether the Rules Wizard is your only place to view all the rules you've created. I had all of my email already sorted into folders and was creating rules for Outlook to automatically move new messages to relevant folders. The Rules Wizard is only displaying the first bunch of rules that I've created; I can't find the ones I made a few minutes ago. What is going on here? If there is a different way to view your rules list, perhaps the new rules are hidden in there. TIA "Truth_Seeker1" <DrewSt...

Creating a ComboBox
I am new to using ComboBox's and need instructions n how to create them I am creating a spreadsheet that requires a comboBox where you ca select either "yes" or "no". Can you help me out -- Message posted from http://www.ExcelForum.com View > Toolbars > Forms For a Yes/No option you would be better using a Check Box Click on Check Box from the Forms Toolbar Drag onto worksheet Right-click on Check Box and select Format Control Click in the Cell-Link box and then click on any cell in the worksheet Click OK When the check box is selected (Yes) the value i...

I need to print my chart BIG...
How do I print a chart larger than 8.5x11 or 11x17? Is there a "tile" option in excel that I'm not seeing somewhere? You know, where it prints on four separate pages and you have to tape them together? Thanks. On Tue, 25 Jul 2006, in microsoft.public.excel.charting, aurorapixiemom <aurorapixiemom@discussions.microsoft.com> said: >How do I print a chart larger than 8.5x11 or 11x17? > >Is there a "tile" option in excel that I'm not seeing somewhere? You know, >where it prints on four separate pages and you have to tape them together? There'...

stacked bar chart #6
I wish to create a horz. stacked bar chart for PC refresh cycles. (unit in years) sample data: installed refresh refresh pc1 2002 2006 2010 pc2 2003 2007 2011 pc3 2002 2006 2010 x: axis = years y: axis = pc1,2 ,3...etc No matter how i create the chart it is always starts with 1905. is there anyway I can create a cimple and easy chart? maybe something similar to grantt chart. many thanks. Jason On Wed, 30 May 2007, in microsoft.public.excel.charting, Jason <Jason@discussions.microsoft.com> said: >installed refresh refr...

bubble charts in Excel 2007
Is there a limit to the number of series defined in a bubble chart? More importantly, I'm attempting to create a bubble chart with 4 columns of data: year, fund, return%, fund size. Can this be done? ...

Exporting Excel Charts in Separate Tabs
I have an excel file with different charts on each tab. The Excel file has at least 20 tabs and I would like to export them into Word as a separate sheet per tab for a reference guide. Is there a way to export from excel without having to cut and paste each tab? I am using MS Office 2003. ...

Net worth report doens't equal Accounts List Total
With all the accounts selected in the report I get two different figures. How can that be? AK2K@mail.ru PS Please CC email In microsoft.public.money, AK wrote: >With all the accounts selected in the report I get two >different figures. How can that be? Try opening Money with Start->Run and entering "msmoney -s" without the quotes into the box. ...

Column Chart labels on all columns
I have a column chart that shows info about a set of items (in this case, projects), which are grouped into categories (business units). I can gen 3 charts for the set of projects, showing data of interest about the projects (staffing, capital cost, expected ROI). Since the projects are grouped by BU, a project 's column has the color associated with its BU. So far so good. The trouble is, on the X axis, I only seem to get every other Column labeled (in this case, with the name of the project). It would be Very Helpful to be able to see *all* of the columns labelled with their pr...

I Need a Blank Chart!
Helllllllp! I have inherited a report at work which automatically produces a Powerpoint presentation of results by picking up charts from within an Excel 2003 spreadsheet. I want to just show a data table rather than an actual chart but I need some of the residual information that is within the grouped chart area to go into the Powerpoint presentation. Is there any way of just showing the data table in a chart format without the actual chart bit! I know this sounds nuts! Pivot tables won't work for this. All help gratefully received! Hi Emma, I would like tha...

Capturing Equations From Charts
I have created a chart that displays Space vs Sales for a given department for a number of stores for the company I work for. To this I have applied a logarithmic trendline to show the curve of how sales change with changes in space & have displayed the equation for this line. What I am wondering is, is there a way to capture this equation in to an Excel cell without manually cutting & pasting it? I have to create a number of these charts for different departments & need to capture the equation for each one & doing it manually is taking forever! If anyone can help, it'd ...

Lead convertable to a new created entity?
Hi Is it possible to convert a Lead to a new entity which is not a firm or contact, but an entity role such as "Building"? Further, will there occur big troubleshooting by overtaking the general data of the lead in the "building" entity? I would like to use the lead for the first research of the building address, contacts,.... Thank you! Afraid there is no built-in support to convert to anything but Contact, Account and/or Opportunity. This is basically tied to the fact that Contact & Account are the only 2 "customer" types in the system that can hav...

VB Question
Is there anyway of writing a macro which when run will give the user a message box for them to enter some data and then put this in an appropriate cell on the spreadsheet? TIA Hi Gav to give you an idea: Sub test_input() ActiveSheet.Range("D1") = InputBox("Enter your value") End Sub wil put the value entered via the inputbox in cell D1 of the active worksheet Gav Dent wrote: > Is there anyway of writing a macro which when run will give the user a > message box for them to enter some data and then put this in an > appropriate cell on the spreadsheet? > &g...

how to create blank empty square cell graph template
I cannot print the simple instructions that I need to replicate 7500 cells each with the same height and width of .1 inch (75 columns and 100 rows). This is to be a template that I can save for multiple uses. There will be no data entered into the template, but I want to open it up from a saved location to fill the cells later at different times with different info, values, data, colors, etc. I want to be able to create the template efficiently using Excel 2007. I believe Microsoft Works allows nothing theoretically square less than a quarter inch. The desired template should fit on 8...

Changing colours in chart
Hi.I have to edit this excelchart, but i have no idea how to do, cause am new in excel The read arey have to be blue and otherwise. http://web3.p15137269.pureserver.info/images/excel/orig.JPG rightclick on the dataserias and then "Format Data series" bringing u this dialog: http://web3.p15137269.pureserver.info/images/excel/prob.JPG Then i change from red to blue. http://web3.p15137269.pureserver.info/images/excel/prob2.JPG And it looks so: http://web3.p15137269.pureserver.info/images/excel/new.JPG If i uncheck "invert if negative" the whole chart is only in on c...

Creating an Array using Percentile Formula
I was hoping that someone could help me out with this one. I want create an excel formula with Percentile that uses an array. The length of the data will vary but the Country names in Column A will always be available. Example: Col (A) - Col (B) Country - Sales Australia - 100 Australia - 200 Australia - 300 Australia - 400 Australia - 500 Brazil - 600 Brazil - 700 Brazil - 800 Brazil - 900 Brazil - 1000 USA - 800 USA - 700 USA - 600 USA - 500 USA - 400 Using the formula "=percentile(array,.5)" how can a create an array to seek out the country names in Col A to get the below res...

2003 vba to hide two grouped charts, works in 2007 but not in 2003
> Hi, Sorry I've copied this over from my post in the Charting newsgroup since there's not much activity there. > I have the following code which works fine in 2007. But since I have > some users that still use 2003, when I save the spreadsheet in 2003 > xls format, this code will no longer work. I found that when I ungroup > the two charts, then it works fine. > > Do I need to use code to Ungroup them first, or is there a simple > solution? > > Thanks, > Harold > > Sub Hide_Two_Charts() > Sheets("Budget").ChartObj...

Select all chart data points
I have made a graph in Excel 97, but I cannot select all data points on the graph. When I click on a data point only every other point (or so) is highlighted. I have deleted the graph and re-entered the data, still no good! If I make a quick temorary graph by opening excel from scratch in a new window this seems to work (click on a point and they all highlight). Is there a default setting somewhere!? Thanks What is it you want to do with the series once you select it? "CL" <clairelead@blueyonder.co.uk> wrote in message news:1106737562.533026.13210@c13g2000cwb.googlegroups.co...

Printing a chart within a worksheet
Hello, I want to display several charts and graphs on one worksheet to make available to non excel users. I would like to create a "Print" button so these users could automatically print the one or two charts they want without having to set the print area manually. I have used hyperlinks so folks could move back and forth from various spreadsheets. Is there a similar type of command where they click on a button that I create so the only print cells A53 to Z53 to A112 to Z112 and maintain the formatting and sizing that I created? Thanks! :) --- Message posted from http://www.Ex...