View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.charting
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Bug with Chart.Name?

The name of an embedded chart is really the chartobject's name. This is what
you change in the name box after shift-click selecting the chart.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"bart13" wrote in message
...

Hi Peter,

I'm doing a loop similar to what you noted, but excluding charts with
the default name of Chart ###

-
For Each Pict In ActiveSheet.ChartObjects

strChartName = RTrim(Pict.Chart.Name)
tChartName = strChartName
ThisChartNum = Val(Right(strChartName, 4))

testFile.WriteLine strChartName

If Left(strChartName, 5) < "Chert" Then
Set ThisChart = Pict.Chart
SaveName = SavePath & strChartName & ".png"


ThisChart.Export Filename:=SaveName, FilterName:="PNG"
Counter = Counter + 1

End If

Next
Set ThisChart = Nothing

testFile.Close
-
(note that the actual non test code does have "Chart" instead of
"Chert")


I haven't done any grouping that I know of and frankly I'm not even
sure what it means in this context.

The truly weird part is that the code usually works and does save the
file just fine. The test tab that I noted has 6 charts in it and three
of them save just fine, but its like the other three (created by just
copying one of the working charts, which itself was copied from another
chart tab, and then editing the name and other attributes like the x
axis via the normal UI ) don't even exist. Their names don't even show
up in the output text file. All the names are shorter than the max 31
character limit.


bart13



Peter T;677490 Wrote:
Could you explain what you mean by "exported". With the chart Export
method
you need to supply a file name for what will be an image of the chart
saved
to disc (unique to avoid over writing). This name is not related to
the
chart name, even though in practice you might use a similar name, eg
"C:\ChartSales01.gif"

Do you mean perhaps copying to some other workbook. Either way, there
can be
problems referencing all chartobjects under relatively rare scenarios
(or
any objects at the drawing object level). The following may reference
different charts,

for each chtObj in ws.chartobjects
vs
for i = 1 to ws.ChartObjects.Count
Set chtObj = ws.Chartobjects(i)

(ws is a reference to the sheet)

One way discrepancies can arise is after first renaming, then grouping,
then
copying then ungrouping. You can end up with multiple chartobjects
having
the same 'new name'.

Normally the For Next loop is more reliable (same as
Chartobjects.count) but
the For Each loop will pick up any chartobjects that are still in a
group
(but can be problematic for different reasons).

Regards,
Peter T






--
bart13