PC Review


Reply
Thread Tools Rate Thread

Create Excel Chart via COM ?

 
 
Andrew Kennard
Guest
Posts: n/a
 
      7th Jul 2003
Hi all

I've had a look through MDSN but cannot see how you create an excel chart
via COM ? is it possible ?

I can see many examples on how to create and save a speadsheet file.

Can someone send me a link etc to point me in the right direction

Thanks in advance

Andrew Kennard




 
Reply With Quote
 
 
 
 
Tushar Mehta
Guest
Posts: n/a
 
      7th Jul 2003
Use XL's macro recorder (Tools | Macro > Record new macro...) to get
the necessary code. Then, stick in a XLObj / workbook (or whatever you
are calling the XL Application object / workbook in your code) in front
of everything.

For example, the XL macro recorder might give you:

Sub Macro1()
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A3")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
End Sub

and you can convert it into:

Option Explicit

Sub modifiedMacro1()
Dim XLObj As Excel.Application, XLWB As Excel.Workbook, _
aChart As Excel.Chart
Set XLObj = CreateObject("Excel.Application")
XLObj.Visible = True
Set XLWB = XLObj.Workbooks.Add
With XLWB.Worksheets(1).Range("a1")
.Offset(0, 0) = 1: .Offset(1, 0) = 2: .Offset(2, 0) = 3
End With
Set aChart = XLWB.Charts.Add
Set aChart = aChart.Location(xlLocationAsObject, _
XLWB.Worksheets(1).Name)
With aChart
.SetSourceData Source:=XLWB.Worksheets(1).Range("a1:a3")
.ChartType = xlColumnClustered
End With
XLWB.Close False
Set XLWB = Nothing
XLObj.Quit
Set XLObj = Nothing
End Sub


--
Regards,

Tushar Mehta (www.tushar-mehta.com) MS MVP -- Excel

In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> Hi all
>
> I've had a look through MDSN but cannot see how you create an excel chart
> via COM ? is it possible ?
>
> I can see many examples on how to create and save a speadsheet file.
>
> Can someone send me a link etc to point me in the right direction
>
> Thanks in advance
>
> Andrew Kennard
>
>
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a baseline in Excel 2007 on Excel Chart Deb Microsoft Excel Charting 1 18th Nov 2008 08:58 AM
Why create a chart in Excel? =?Utf-8?B?bGFuZXk=?= Microsoft Excel New Users 5 13th Apr 2007 06:06 PM
How can I create a 4D chart in excel? =?Utf-8?B?QW5uZWxpIFRvdWFydA==?= Microsoft Excel Charting 0 23rd Feb 2006 10:39 AM
How to create a z chart in excel ? =?Utf-8?B?QmlsYWw=?= Microsoft Excel Charting 4 30th Jan 2006 10:56 AM
How to create a link between(Excel) Gantt chart and Excel source =?Utf-8?B?TWFn?= Microsoft Excel Setup 2 16th Dec 2005 04:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 PM.