You probably don't have a chart with that name on every sheet you're testing.
Try something like this
Dim shtcnt As Long
Dim aWB As Workbook
Dim myWS As Worksheet
Dim ChtObj As ChartObject
Set aWB = ActiveWorkbook
For shtcnt = 2 To (aWB.Sheets.Count - 1)
Set myWS = aWB.Sheets(shtcnt)
For Each ChtObj In myWS.ChartObjects
If ChtObj.Name = "xyz chart" Then
ChtObj.Select
End If
Next ChtObj
Next shtcnt
--
HTH,
Barb Reinhardt
If this post was helpful to you, please click YES below.
"Scooter" wrote:
> The code at the bottom use to work in Excel 2003 but now in Excel 2007 I get
> the error message when it executes the ActiveSheet line:
>
> Run-time error '1004':
> Application-defined or object-defined error
> ---------------------------------------------------------------------------------------------
> dim shtcnt as integer
>
> For shtcnt = 2 To (ActiveWorkbook.Sheets.Count - 1)
> ActiveWorkbook.Sheets(shtcnt).Select
> ActiveSheet.ChartObjects("xyz chart").Select
> ---------------------------------------------------------------------------------------------
> I have verified that "xyz chart" exists by selecting the chart with Alt +
> mouse click and seeing the name in the Name Box left of the Formula Bar. Any
> ideas whats wrong?
>
|