Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel chart: xlLocationAsObject not behaving 1

Status
Not open for further replies.

kndavies

Technical User
Jan 23, 2003
30
GB
Hi,

Struggling with this one for hours...

Excel 2000/Access 2000/Windows 2000
Running Excel from Access

I'm adding a chart and need it to be within an existing sheet so:

with xlsApp.application
<code working>
.Charts.Add
.ActiveChart.Location Where:=xlLocationAsObject, "Event Chart"
<code working>

However it refuses to add the chart to the Sheet ("Event Chart") and instead puts it into the first sheet of the workbook.

All help appreciated.

Ken



 
I think you need to use the ChartObjects collection to embed a chart onto a worksheet, instead of the Chart object. Charts.Add is like adding a new 'Chart Sheet' to your workbook. If objXL is your Excel.Application object:

Dim chrtobj as Object
Dim objSht as Object

Set objSht = objXL.Activeworkbook.Sheets("Event Chart")
' Numbers are Left, Top, Width, and Height in points.
Set chrtobj = objSht.ChartObjects.Add(100, 100, 200, 200)
With chrtobj.Chart
.FormatChart blah blah
End With

Ken
 
Ken,

That's exactly what I needed. Many thanks and have a star :)

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top