代码之家  ›  专栏  ›  技术社区  ›  Kram Kramer

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

  •  0
  • Kram Kramer  · 技术社区  · 5 月前

    如何更改Chart xAxes字体颜色 黑色 红色 通过vba代码?

    下图显示了我的问题。

    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
    
    1 回复  |  直到 5 月前
        1
  •  1
  •   Tim Williams    5 月前

    例如:

    Dim cht As Chart
    Set cht = ActiveSheet.ChartObjects(1).Chart
    cht.Axes(xlValue).TickLabels.Font.Color = vbRed