如何通过vba代码将图表xAxes字体颜色从黑色更改为红色?

问题描述 投票:0回答:1

如何通过vba代码将图表xAxes字体颜色从black更改为red

下图就是我的问题。

picture

我尝试了以下代码,但没有成功。

Public Sub Macro1()

'Delete all charts
For i = ActiveSheet.Shapes.Count To 1 Step -1
    If ActiveSheet.Shapes(i).Type = msoChart Then
        ActiveSheet.Shapes(i).Delete
    End If
Next i

'Add a chart.
With ActiveSheet.ChartObjects.Add(Left:=10, Top:=10, Width:=600, Height:=400)
    .Chart.ChartArea.Format.TextFrame2.TextRange.Font.Size = 20
End With

'Add a serie.
With ActiveSheet.ChartObjects(1).Chart.SeriesCollection.NewSeries
    .ChartType = xlLine
    .XValues = Array(1, 2, 3, 4, 5)
    .Values = Array(150000, 20000, 80000, 120000)
End With

'Axes(xlValue) settings.
With ActiveSheet.ChartObjects(1).Chart.Axes(xlValue)
    'The following line throws an error. How to solve this error?
    '.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = vbRed
End With

End Sub
excel vba graph charts
1个回答
0
投票

例如:

Dim cht As Chart
Set cht = ActiveSheet.ChartObjects(1).Chart
cht.Axes(xlValue).TickLabels.Font.Color = vbRed
© www.soinside.com 2019 - 2024. All rights reserved.