[英]Excel VBA breaking from Sub call
我有一个名为“GFATMEN”的ChartObject,当我检查电子表格中的某些表单控件复选框时,需要更新图例。 它们正被使用,因此我可以在图表上显示或不显示某些数据,我需要显示或不显示图例。
例如,单击一个复选框时,我有这个子:
Private Sub MerT_Click()
Application.ScreenUpdating = False
On Error Resume Next
ActiveSheet.ChartObjects("GFATMEN").Activate
If ActiveSheet.SeriesCollection.Count = 3 Then
With ActiveChart
If MerT = False Then
.SeriesCollection(3).Format.Line.Visible = msoFalse
Call show_legend
Else
.SeriesCollection(3).Format.Line.Visible = msoTrue
Call show_legend
End If
End With
End If
Application.ScreenUpdating = True
End Sub
它调用另一个子show_legend
,重新创建图例并对其进行格式化:
Sub show_legend()
ActiveSheet.ChartObjects("GFATMEN").Activate
With ActiveChart
.HasLegend = False
.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.Legend.Font.Name = "Tahoma"
.Legend.Font.Size = 10
.Legend.Font.ForeColor.Brightness = 0.25
End With
If MerT = False Then ActiveChart.Legend.LegendEntries.Item(3).Delete
If MerE = False Then ActiveChart.Legend.LegendEntries.Item(2).Delete
If MerI = False Then ActiveChart.Legend.LegendEntries.Item(1).Delete
End Sub
问题是,只要读取.Legend.Font.ForeColor.Brightness = 0.25
行,代码ALWAYS就会从show_legend
子show_legend
断开并返回到前一个子.Legend.Font.ForeColor.Brightness = 0.25
。 我已经在.HasLegend = True
行之后的前一部分放了这行,并且同样的事情发生了。
我找不到任何与我的问题相关的答案。 谢谢。
您可以尝试类似下面的代码:
With .Chart.Legend
.Position = xlLegendPositionBottom
.Font.Size = 10
.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) '<-- modify the font color
.Format.TextFrame2.TextRange.Font.Fill.ForeColor.Brightness = 0.25 '<-- modify the font brightness
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.