我试图使错误栏透明......代码可以使单个工作表上的单个图表上的错误栏透明,但理想情况下我希望这可以在不同的工作表上循环遍历多个Excel图表。
Sub Macro2()
Dim objCht As ChartObject
For Each objCht In ActiveSheet.ChartObjects
ActiveChart.SeriesCollection(1).HasErrorBars = True
ActiveChart.SeriesCollection(1).ErrorBars.Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = -0.0500000119
.ForeColor.Brightness = 0
.Transparency = 1
End With
Next objCht
End Sub
答案 0 :(得分:1)
尝试以下代码,无需使用Select
:
Sub Macro2()
Dim objCht As ChartObject
Dim ws As Worksheet
' loop through sheets in this workbook
For Each ws In ThisWorkbook.Worksheets
' loop through Chartobjects in sheet
For Each objCht In ActiveSheet.ChartObjects
' no need to select the chart or the series use With statement instead
With objCht.Chart.SeriesCollection(1)
.HasErrorBars = True
With .ErrorBars.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = -0.0500000119
.ForeColor.Brightness = 0
.Transparency = 1
End With
End With
Next objCht
Next ws
End Sub
答案 1 :(得分:0)
您只需要为所有工作表添加一个循环。像这样:
Dim objCht As ChartObject
For Each ws In ThisWorkbook.Worksheets
For Each objCht In ws.ChartObjects
ActiveChart.SeriesCollection(1).HasErrorBars = True
ActiveChart.SeriesCollection(1).ErrorBars.Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = -0.0500000119
.ForeColor.Brightness = 0
.Transparency = 1
End With
Next objCht
Next ws