[英]How do I change the background image of a chart in vba?
I need to change the background image of a chart I created using vba. 我需要更改使用vba创建的图表的背景图像。 I tried using the .Fill command but I can't make it work. 我尝试使用.Fill命令,但无法正常工作。 How do I do it? 我该怎么做? This is the code I used to create the chart and it is working fine: 这是我用来创建图表的代码,它工作正常:
With myChart
.ChartStyle = 245
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = ""
.HasLegend = False
.Axes(xlCategory).HasTitle = True
.Axes(xlCategory).AxisTitle.Text = "Punteggio Tecnico"
.Axes(xlValue).HasTitle = True
.Axes(xlValue).AxisTitle.Characters.Text = "Punteggio Economico"
.Axes(xlCategory).MinimumScale = 0
.Axes(xlCategory).MaximumScale = 1
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 1
.SeriesCollection(1).XValues = "=Dati2!B3:B270"
.SeriesCollection(1).Values = "=Dati2!C3:C270"
End With
If myChart
is Chart
variable then you want the myChart.PlotArea.Format.Fill
for the area of the chart that contains the actual chart, or myChart.ChartArea.Format.Fill
for the whole chart area. 如果myChart
是Chart
变量,则需要myChart.PlotArea.Format.Fill
作为包含实际图表的图表区域,或者是myChart.ChartArea.Format.Fill
作为整个图表区域。
The code below shows how to use it. 下面的代码显示了如何使用它。 I've commented out the colouring code that a macro recorder would supply and replaced with a basic RGB value. 我已经注释掉了宏记录器将提供的着色代码,并将其替换为基本的RGB值。
Sub Test()
Dim myChart As Chart
Set myChart = Sheet1.ChartObjects("Chart 2").Chart
With myChart
With .PlotArea.Format.Fill
.ForeColor.RGB = RGB(255, 0, 0)
' .Visible = msoTrue
' .ForeColor.ObjectThemeColor = msoThemeColorAccent6
' .ForeColor.TintAndShade = 0
' .ForeColor.Brightness = 0.400000006
' .Solid
End With
With .ChartArea.Format.Fill
.ForeColor.RGB = RGB(0, 255, 0)
' .Visible = msoTrue
' .ForeColor.ObjectThemeColor = msoThemeColorAccent6
' .ForeColor.TintAndShade = 0
' .ForeColor.Brightness = 0.400000006
' .Transparency = 0
' .Solid
End With
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.