2

I am running an Excel macro in a C# program. I have a chart and I'd like to change its properties.

Here's the code I've tried:

ActiveSheet.ChartObjects("myChart").Activate
ActiveChart.Axe(xlCategory).Select

With Selection.Format.TextFrame2.TextRange.Font  'Run-Time error: method of object failed 
     .BaselineOffset = 0
     .Bold = msoTrue
     .Size = 12
     .Italic = msoFalse
End With

However using the With-EndWith statemnt is giving me a run-time error. Therefore, I'd like to know if there is any code that is equivalent to the code above. I am using Excel 2013.

Pawel Czyz
  • 1,651
  • 4
  • 17
  • 21
Mint.K
  • 849
  • 1
  • 11
  • 27

1 Answers1

2

if your goal is to simply change TickLabels font, may try something like this

ActiveSheet.ChartObjects("myChart").Activate
Dim Axx As Axis
Set Axx = ActiveChart.Axes(xlCategory)
With Axx.TickLabels.Font
     .Bold = True
     .Size = 12
     .Name = "Bookman Old Style"
     .Italic = False
     .Color = RGB(255, 0, 0)
End With
Ahmed AU
  • 2,757
  • 2
  • 6
  • 15