循环工作表并格式化图表1:运行时错误

时间:2014-06-27 20:32:20

标签: vba loops for-loop charts each

我写了一个图表格式化宏,它在应用于特定工作表时有效,我正在尝试在每个循环中使用它。该宏应该循环遍历一个工作表列表,并且只格式化图表1.我在此行收到“运行时错误438:对象不支持此属性或方法”:

.ActiveChart.Shapes("TextBox 1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change"

这是我的每个循环:

Sub UpdateTextAllStateCharts()
'This macro loops through worksheets in a list and performs the assigned task
Dim sheet_name As Range
For Each sheet_name In Sheets("WS").Range("C:C")
    If sheet_name.Value = "" Then
        Exit For
    Else
        With Sheets(sheet_name.Value)
            .ChartObjects("Chart 1").Activate
            .ActiveChart.Shapes("TextBox 1").TextFrame.Characters.Text = "Bodily Injury (BI) Liability Claim Trends" & vbLf & " 2005-" & Range("K5").Value & " Percentage Change" 
           .ChartObjects("Chart 1").Activate
           With ActiveChart.Shapes("TextBox 1").TextFrame.Characters
           With .Font
           .Name = "Calibri"
           .Size = 14
           .FontStyle = "Regular"
           End With
           With ActiveChart.Shapes("TextBox 1").TextFrame
           With .Characters(42, 68).Font
          .FontStyle = "Italic"
          .Size = 12
          End With
          End With
          End With
        End With
    End If
    Next sheet_name
End Sub

此行也会导致同样的错误:

With .Characters(42, 68).Font

提前感谢您的帮助。

此致

0 个答案:

没有答案