1

I am looking for a way to reinstate the default/native resizing behaviour of a chart in Excel 2010 once it has been disabled (e.g. by manipulating the chart with VBA).

Now I haven't been able to find anything anywhere about the behaviour I have in mind, so I am going to assume that it needs detailed explanation.

Input and select random numerical data into 4-5 cells in Excel, and insert a new Clustered Columns chart. You need to see a the chart's plot area. Now select the chart, and get the PlotArea.Top value with the following line

ActiveChart.PlotArea.Top

If you haven't touched the chart, this should return a value of 7. Now use one of the chart's handlebars to resize the chart vertically, and use the same command line again.

activechart.plotarea.top

Notice how the value returned is still 7. Now set this property to 7 in VBA.

ActiveChart.PlotArea.Top = 7

Again, grab one of the handlebars, resize the chart vertically and get the .top property again using:

ActiveChart.PlotArea.Top

Notice how the value has now changed. It will be either smaller or greater than 7 depending on whetehr you decreased or increased the size of the chart.

Once any element of a chart has been moved either manually or with VBA code, it loses this "absolute position" property and begins moving inside the ChartArea whenever the chart is resized. While some elements can be reset using .SetElement, this does not work for the Plot Area. For example, the following command lines do not reinstate the behaviour I am describing.

ActiveChart.SetElement msoElementPlotAreaNone
ActiveChart.SetElement msoElementPlotAreaShow

I do a lot of automated resizing of charts with VBA, and having the plot area move around by itself makes it a lot harder to predict the effect of resizing the chart and leads to inconstant results.

So back to the question: does anyone know of a way to reinstate this default behaviour, either for the entire chart, or at least specifically for the PlotArea?

Thanks in advance to anyone who may help!

Vincent

3
  • I've had mixed results using ActiveChart.ClearToMatchStyle Commented Jan 29, 2015 at 16:40
  • Thanks for the suggestion! Unfortunately it doesn't work in my situation (eg. For the Plot Area) Commented Jan 29, 2015 at 16:56
  • Yeah... Excel is like that sometimes. Commented Feb 12, 2015 at 4:30

1 Answer 1

2

I ran into this when I manually resized the plot area and then when the legend is moved it did not resize the plot area at all.

I had tried to save my chart as a template (right click save as template in Excel 2013) but this still had the plot area manually set.

Therefore I would recommend keeping the auto-size behavior before saving a template, since the only way I know to re-set the chart auto-sizing behavior after it has been manually modified is to use a macro

Here is the macro I used to reinstate the auto-sizing behavior

Sub Macro1()
'
  ' this selects the chart based on the chart name
  ActiveSheet.ChartObjects("Chart 4").Activate
  ' this selects the plot area
  ActiveChart.PlotArea.Select
  ' this clears any custom formatting such as borders or fill colors
  ActiveChart.PlotArea.ClearFormats
  ' this resets the auto-sizing behavior after plot area manually re-sized
  ActiveChart.PlotArea.Position = xlChartElementPositionAutomatic
End Sub

References

Sign up to request clarification or add additional context in comments.

1 Comment

wow, can't believe someone finally figured this out :) after a little bit of testing the xlChartElementPositionAutomatic attribute looks exactly like what I was looking for. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.