【问题标题】:Setting the color of AutoShapeType within a chart in PowerPoint在 PowerPoint 图表中设置自选图形类型的颜色
【发布时间】:2023-01-05 08:13:06
【问题描述】:

我需要更改连接到图表中数据标签的自动形状类型的颜色。

我有这个代码来格式化图表,但我找不到更改自动形状类型颜色的代码。

Sub Format_linechart_smoothlines()

    Dim sld As Slide
    Dim shp As Shape
    Dim chart As chart
    Dim sr As Series
    Dim i As Long
    
    Set sld = Application.ActiveWindow.View.Slide
    
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set chart = shp.chart
            For i = 1 To chart.SeriesCollection.Count
                Set sr = chart.SeriesCollection(i)
                sr.Smooth = True
                sr.Format.Line.Weight = 3
                sr.HasDataLabels = True
                sr.DataLabels.Position = xlLabelPositionCenter
                sr.DataLabels.Font.Color = RGB(255, 255, 255)
                sr.DataLabels.Font.Size = 10
                sr.DataLabels.Format.AutoShapeType = msoShapeRectangle
            Next i
        End If
    Next shp
End Sub

我还尝试在不同的宏中更改形状的颜色,但它不会更改图表中形状的颜色:

Sub ChangeRectangleShapes_Color()

    Dim sld As Slide
    Dim shp As Shape
    
    Set sld = Application.ActiveWindow.View.Slide

    For Each shp In sld.Shapes
      If shp.AutoShapeType = msoShapeRectangle Then
        shp.Fill.ForeColor.RGB = RGB(0, 0, 0)
      End If
  Next shp

End Sub

【问题讨论】:

  • 我不确定您是否了解图表模板。您可以创建示例图表,应用您的自定义格式,然后将其另存为模板(右键单击,选择另存为模板)。然后,在使用中将该模板应用于现有图表,或从中创建新图表,它就会具有您的自定义格式。比尝试使用 VBA 格式化要容易得多。

标签: vba charts powerpoint


【解决方案1】:

要为数据标签设置填充颜色,请尝试...

sr.DataLabels.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)

根据需要更改颜色。

【讨论】:

    猜你喜欢
    • 2016-10-06
    • 2019-09-15
    • 2017-01-18
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多