Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am stuck with a critical issue as explained below:

I am developing a chart programmatically that is saved in an Excel Worksheet with the help of Excel Interop in .Net.

But I cannot use the subscript property of the axis title so that only a part of the title is shown as subscripted and rest will be normal font.

ie.

Dim MyChart As Excel.Chart = CType(MyWorksheet.ChartObjects(1), Excel.ChartObject).Chart

Dim MyAxis As Excel.Axis = CType(MyChart.Axes(Excel.XlAxisType.xlValue), Excel.Axis)

MyAxis.AxisTitle.Text = "cmax"

MyAxis.AxisTitle.Characters(2,3).Font.Subscript = True


Now the above line makes the whole tittle subscripted as if there is no difference in writing the code as :

AxisTitle.Characters().Font.Subscript = True

Any help will be extremely appreciated
Posted
Updated 13-Aug-10 3:46am
v2
Comments
Dalek Dave 13-Aug-10 9:46am    
Minor Edit for Spelling and Code Block.

1 solution

This code seems to work in VBA.
VB
ActiveSheet.ChartObjects("Chart 1").Activate
With ActiveChart.Axes(xlCategory)
    .HasTitle = True
    With .AxisTitle
                .Caption = "Revenue (millions)"
                .Font.Name = "bookman"
                .Font.Size = 10
                .Characters(10, 8).Font.Subscript = True
    End With
End With


The only difference is caption vs. text and .HasTitle must be true or the object doesn't exist.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900