How to change an excel chart axis alignmen in VB.Net?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: How to change an excel chart axis alignmen in VB.Net?

Hybrid View

  1. #1
    Join Date
    Sep 2003
    Posts
    4

    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.

  2. #2
    Join Date
    Dec 2002
    Posts
    305
    With Range("G1")
    .Orientation = 45
    End With

  3. #3
    Join Date
    Sep 2003
    Posts
    4
    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?

  4. #4
    Join Date
    Dec 2002
    Posts
    305
    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

  5. #5
    Join Date
    Sep 2003
    Posts
    4
    Where is With Statement? or With what? chart? sheet? or range?

    Thanks!

  6. #6
    Join Date
    Dec 2002
    Posts
    305
    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.

  7. #7
    Join Date
    Sep 2003
    Posts
    4
    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.

  8. #8
    Join Date
    Dec 2002
    Posts
    305
    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.

  9. #9
    Join Date
    Nov 2012
    Posts
    1

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center