VBA and Chart Legends (2003 and 2007)

B

Barb Reinhardt

I have this snippet of code to update the legends to the bottom of the chart

For Each objCht In WS.ChartObjects
With objCht.Chart
.Legend.Position = xlLegendPositionBottom
End With
Next objCht

If I record this in 2003 OR 2007, I get this

ActiveChart.Legend.Select
Selection.Position = xlBottom

But if I type .Legend.Position in the original snippet,
xlLegendPositionBottom is an option and xlBottom is not an option. In
Office 2007, it appears to Gack on xlLegendPositionBottom and prefers
xlBottom. Is this a bug, or am I missing something?

Thanks,

Barb Reinhardt
 
A

Andy Pope

Hi,

Not a bug but a difference between referencing the Legend object position
property and the Selection object.

xlLegendPositionBottom and xlbottom both return the same value, -4107


Cheers
Andy
 
B

Barb Reinhardt

I'm getting reports that it gives a run time error when
xlLegendPositionBottom is being used.
 
A

Andy Pope

In my quick test using either constant in both code examples worked.

Do you have more details when failing, such as chart and data type.

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top