Chart size generated by my

helene -  
 Thibault56 -
Hello,
I have a macro that automatically generates charts. However, the size of the chart window imposed on me doesn't suit me.
With the macro recorder, I found how to modify the size:

ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 22").ScaleWidth 1.39, msoFalse, _
msoScaleFromTopLeft

However, since I generate several charts on the same sheet, I never know the number of the created chart.
So I would like to replace "Chart 22" in these few lines with a generic term so that the size of the selected chart (the one I am currently creating) is modified.

Thank you for your help!
Configuration: Windows XP Internet Explorer 6.0

2 answers

Dragor
 
Hello,

I had the same issue as you did, to answer your question, you can call the last created chart using the ActiveSheet.Shapes.count option; this returns the number of charts so the number of the last one directly if you call:
ActiveSheet.Shapes(ActiveSheet.Shapes.count).ScaleWidth 1 etc...

There you go.
1
Thibault56
 
This problem is quite common. Here is a solution I adopted:
We count the number of charts on the sheet in order to rename the last one that was created
'--Renaming the chart for automation
NbGraph = ActiveSheet.ChartObjects.Count 'Counts the number of charts in the sheet

Then we select the last one created and give it the name we want (which can actually change if you create multiple charts)
ActiveSheet.ChartObjects(NbGraph).Name = "Graph_error_" & i 'Gives the name to the chart with i that changes for each chart
0