1

我在 Excel VBA 中遇到了一些问题。当我尝试运行以下代码时;它说:

Error 1004:Unable to get the name property of the series class!

此错误发生在这行代码:(产品之前定义为字符串 Zyvox 等)

If namec.Name = product Then

我应该怎么办?我也尝试过其他的东西

   ActiveChart.SeriesCollection(p).name = product

但无济于事!请帮忙!

Public Sub chartBlue()

Dim i As Integer, j As Integer, p As Integer, namec As Series


For i = 4 To Sheets.Count
    Sheets(i).Activate
    For j = 1 To Sheets(i).ChartObjects.Count
        Sheets(i).ChartObjects(j).Activate
        ActiveChart.ChartArea.Select


        For p = 1 To ActiveChart.SeriesCollection.Count
        Set namec = ActiveChart.SeriesCollection(p)


            If namec.Name = product Then
               namec.Border.ColorIndex = 5

            End If

        Next p
    Next j
  '  Windows(Reportname).Activate
    Sheets(i).Range("A1").Activate
Next i

End Sub
4

1 回答 1

2

Amit,我在示例工作表上运行了您的代码,它运行良好!唯一缺少的是变量的声明和设置product,但你提到你做到了。所以,首先确保它product被声明为字符串并且有内容。然后,在该行中设置一个断点

如果 namec.Name = 产品 那么
并运行代码。检查两者的内容,namec.Nameproduct查看其不同之处

于 2013-01-31T11:17:52.297 回答