在工作中,我总共有 72 个 Excel 2010 工作簿,每个有 12 个工作表,每个工作表上都有一个图表(我认为这意味着图表没有嵌入?)。我是一名基础程序员,只在 A-Level 学习过 VB。
我需要工作簿中的所有图表(在 12 个单独的工作表上)具有与该工作簿中的第一个图表相同的颜色数据线。
我最初的想法是记录我手动更改线条颜色、粗细等的宏,然后查看该宏的代码并在其周围放置某种循环。
经过数小时尝试不同的建议和许多谷歌搜索后,我无法让它发挥作用。
我到目前为止的代码如下:
Sub Macro1()
Dim i As Integer
Dim sht As Worksheet
For i = 1 To ActiveWorkbook.Worksheets.Count
Set sht = ActiveWorkbook.Sheets(i)
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(1).Select
ActiveChart.SeriesCollection(1).Select
With Selection
.MarkerStyle = 2
.MarkerSize = 7
End With
Selection.MarkerStyle = -4168
Selection.Format.Fill.Visible = msoFalse
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.Weight = 1.25
End With
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(2).Select
ActiveChart.SeriesCollection(2).Select
With Selection
.MarkerStyle = 1
.MarkerSize = 7
End With
Selection.MarkerStyle = -4168
Selection.Format.Fill.Visible = msoFalse
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.Weight = 1.25
End With
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(3).Select
ActiveChart.SeriesCollection(3).Select
With Selection
.MarkerStyle = 3
.MarkerSize = 7
End With
Selection.MarkerStyle = -4168
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
' .ForeColor.Brightness = 0
.Solid
End With
With Selection.Format.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.Weight = 1.25
End With
Selection.Format.Fill.Visible = msoFalse
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(4).Select
ActiveChart.SeriesCollection(4).Select
With Selection
.MarkerStyle = -4168
.MarkerSize = 7
End With
Selection.Format.Fill.Visible = msoFalse
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(112, 48, 160)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.Weight = 1.25
End With
Next i
End Sub
此代码运行并执行我想要的操作,但仅在您实际在 excel 中打开的工作表上运行,它不会在工作簿中的每个工作表上运行和运行宏。有任何想法吗?
提前致谢