2017-01-31 46 views
1

我有一个名为“GFATMEN”的ChartObject,当我检查电子表格中的某些表单控件复选框时,需要更新图例。他们正在使用,所以我可以在图表上显示或不显示某些数据,并且我需要显示或不显示图例。Excel VBA打破子电话

例如,我有这样子被点击复选框时:

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就返回到前一个子代。我已经把这一行放在前一节,紧接在.HasLegend = True行之后,同样的事情发生了。

我找不到与我的问题相关的任何答案。谢谢。

+0

的复选框单纯和梅里都类似潜艇到梅特。 –

+1

你从哪里得到该代码?没有'Font.ForeColor'属性。 – Rory

+0

这行代码可能会抛出一个错误,因为您在'MerT_Click'子文件中有'On Error Resume Next',因此将被忽略。 – Socii

回答

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