如何通过vba代码将图表xAxes字体颜色从black更改为red?
下图就是我的问题。
我尝试了以下代码,但没有成功。
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
例如:
Dim cht As Chart
Set cht = ActiveSheet.ChartObjects(1).Chart
cht.Axes(xlValue).TickLabels.Font.Color = vbRed