使多个Excel图表中的错误栏透明

我试图使错误栏transparrent …代码工作,使单个工作表上的单个图表上的错误栏透明,但理想情况下,我想这样循环通过多个不同的工作表上的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 

所有的工作表只需要一个循环。 像这样的东西:

 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 

试试下面的代码,没有必要使用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