-
September 22nd, 2003, 10:25 AM
#1
How to change an excel chart axis text orientation in VB.Net?
Hi, I am developing a VB.Net application that will populate data from database to excel and create an excel chart base on the data. I already got excel data and chart, but I need to change one axis text orientation to 45 degree. How can I do that in VB code? Thanks for the help!
Last edited by mrtxu; September 22nd, 2003 at 10:59 AM.
-
September 23rd, 2003, 05:34 AM
#2
With Range("G1")
.Orientation = 45
End With
-
September 23rd, 2003, 08:30 AM
#3
Thanks Gizmo001! But what I need is to change the axis lable text orientation on the chart to 45 degree, not the text orientation in excel. Any idea about that?
-
September 23rd, 2003, 02:40 PM
#4
Try this (for x-axis) with appropriate changes to the first line (depending on your Excel chart name):
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlCategory).AxisTitle
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Orientation = 45
End With
and for y-axis
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Axes(xlValue).AxisTitle
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlContext
.Orientation = 45
End With
-
September 23rd, 2003, 02:58 PM
#5
Where is With Statement? or With what? chart? sheet? or range?
Thanks!
-
September 23rd, 2003, 03:08 PM
#6
Sorry, with statement should begin with the Activechart line. For example if your active chart is named xlchart
With xlchart.Axes(xlvalue).axistitle
.orientation =45
end with
By the way, go to Excel, turn macro tool on, and record the macro as you rotate the axis label on the chart. After rotation is complete, stop recording macro. Then edit macro to see the visual basic code created. You can bring this code into VB.Net with minor variations with respect to the object names: Excel sheet name, chart name, etc. For any Excel command/function that you want to implement in VB, this is a good way to find the syntax.
Good luck.
-
September 23rd, 2003, 03:41 PM
#7
Sorry to bother again Gizmo001! My VB.Net won't recognize Axes(xlCategory) saying xlCategory not defined. And also ActiveChart, ActiveSheet, etc. I am thinking maybe I need to import some special classes. But I can get regular chart on the sheet already. I am so confused. Since the X axis label is now showing horizontally its not showing all on the chart when taking larger numbers of rows from excel. That's the reason I want to change its orientation to 45 degree or 90 degree. Although I can manually change that in excel I still think there should be a way in VB.Net coding.
-
September 25th, 2003, 02:34 PM
#8
Sorry, I tried to check it out, and it didn't work either. It used to work with earlier verisions of Excel reference library (8.0 Object library), but with 10.0, it does not work. I have not been able to figure out the equivalent syntax for the new Excel library.
-
November 18th, 2012, 09:34 PM
#9
Re: How to change an excel chart axis alignmen in VB.Net?
You need to reference the Microsoft.Office.Core namespace, ie.
.ReadingOrder = Microsoft.Office.Core.XlReadingOrder.xlContext
-
January 4th, 2021, 09:13 AM
#10
Re: How to change an excel chart axis alignmen in VB.Net?
Change category label text on the worksheet
On the worksheet, click the cell that contains the name of the label that you want to change.
Type the new name, and then press ENTER.
Note Changes that you make on the worksheet are automatically updated in the chart.
Change the label text in the chart
In the chart, click the horizontal axis, or do the following to select the axis from a list of chart elements:
Click anywhere in the chart.
This displays the Chart Tools, adding the Design and Format tabs.
On the Format tab, in the Current Selection group, click the arrow in the Chart Elements box, and then click the horizontal (category) axis.
On the Design tab, in the Data group, click Select Data.
In the Select Data Source dialog box, under Horizontal (Categories) Axis Labels, click Edit.
In the Axis label range box, do one of the following:
Specify the worksheet range that you want to use as category axis labels.
Type the labels that you want to use, separated by commas — for example, Division A, Division B, Division C.
Click OK.
I hope this information will be helpful!
Tim Paine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|