View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toby Erkson Toby Erkson is offline
external usenet poster
 
Posts: 32
Default How to name a chart for referencing in VBA? And move it.

I'm trying to modify the macro recording by making it an object, as such (ignore the leading numbers, I'll explain in a second):

Dim chartAvgCalls As Chart
Set chartAvgCalls = Charts.Add
chartAvgCalls.SetSourceData Source:=Sheets("Pivots").Range("B7")
chartAvgCalls.Location Whe=xlLocationAsObject, Name:="Charts"
1 With chartAvgCalls
1 .HasPivotFields = False
1 .PlotArea.Select
1 End With
2 With Selection.Border
2 .ColorIndex = 16
2 .Weight = xlThin
2 .LineStyle = xlContinuous
2 End With
...
Okay, the statements prefixed with number 1 don't work, they give me an Automation error. The statements prefixed with the number 2 do work. Excel's Help
wasn't very helpful about the Automation error.

Suggestions?
TIA,
Toby Erkson
Oregon, USA

On Tue, 27 Apr 2004 16:09:40 -0700, Toby Erkson < wrote:

I'm using the macro recorder to create a pivot chart. I want to do some of my own stuff like move it to a certain location, however, the macro recorder
classifies it as a Shape, for example:

...chart creation goes here...
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart30").IncrementLeft -229.5
ActiveSheet.Shapes("Chart30").IncrementTop -154.5
...

I would like to give the chart a name instead of a generic number like the macro recorder assignees (and increments :-( ). Also, how would I take that named
chart and move it to a specific location, like a cell reference ("A1" or "P30")?

I looked to Chip's page http://www.cpearson.com/excel/codemods.htm but it didn't help me for naming a chart.
Toby Erkson
Oregon, USA