views:

5682

answers:

3

Hi,

I have to make column charts in Excel using VBA only (no user input). I wanted to format the labels of the x-axis so that the alignment for every label becomes -270 degrees. (This can be done manually by changing the "Custom angle" property in the "Alignment" tab of the "Format Axis" Dialog.) I have tried recording a macro for this but Excel does not seem to be recording the alignment step. Does anybody know how to do this with VBA only?

+2  A: 

If you are using Excel 2007, try using an earlier version because 2007's macro recorder is a bit crippled.

This is what I got:

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.Orientation = xlUpward
Artelius
That did the trick :) Thanks a lot. (... and to think I was afraid that an option may not exist)
Kshitij
Thanks @artelius, i just came across the same problem with Excel 2007.
Mark Nold
You can simplify this to: `ActiveSheet.ChartObjects("Chart 1").Chart.Axes(xlCategory).TickLabels.Orientation = xlUpward` and avoid activating and selecting, which improves performance and leaves the clipboard contents alone.
e100
A: 

What if I want another angle? Say -67? How do I tell excel to incline my x axis labels -67 degrees?

Carlos H
A: 
ActiveChart.Axes(xlCategory).TickLabels.Orientation = 67
Kyle