我有一个名为" GFATMEN"当我检查电子表格中的某些表单控件复选框时需要更新图例。它们正被使用,所以我可以在图表上显示或不显示某些数据,我需要显示或不显示图例。
例如,当点击一个复选框时,我有这个子:
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
问题是每当读取行show_legend
时,代码总是从.Legend.Font.ForeColor.Brightness = 0.25
sub断开并返回到前一个sub。我已经在.HasLegend = True
行之后的前一部分放了这一行,同样的事情发生了。
我无法找到与我的问题相关的任何答案。谢谢。
答案 0 :(得分:0)
您可以尝试以下代码:
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