Chart Activate Problem

  • Thread starter Thread starter Phil Hageman
  • Start date Start date
P

Phil Hageman

On a worksheet named Customer, is a Button (among other
buttons) with a macro named "GoToMetric1" assigned to it.
The macro code is located in Module2 and the code is:

Sub GoToMetric1()
Sheets("Metrics").Select
Range("A1").Select
ActiveSheet.ChartObjects("Chart 13").Activate
With ActiveChart.Parent
.Height = 660
.Width = 780
.Top = 10
.Left = 125
End With
End Sub

On the worksheet named Metrics, are various charts, with
Chart 13 displaying data.

The intent is when the user clicks on the Button, Chart 13
(among the charts) on the Metrics worksheet comes up, and
the cursor locates in A1; however, I'm getting a run-time
error '1004': "Activate method of ChartObject class
failed." The line "ActiveSheet..." is highlighted yellow.
Further confusing this is the fact that sometimes this run-
time error does not occur. Can someone help me correct
this error?

There is also an Auto Open routine being run when the
workbook opens, located in Module1. I don't think there is
a conflict with it, but the code is:

Sub Auto_Open()
Application.ScreenUpdating = False
Application.DisplayFullScreen = True
For Each ws In Worksheets
If ws.Visible = xlSheetVisible Then
ws.Select
Application.GoTo ws.Range("A1"), True
ActiveWindow.DisplayGridlines = False
End If
Next
Worksheets("Scorecard").Select
ThisWorkbook.Colors(7) = RGB(255, 124, 128)
Application.AutoPercentEntry = True
Application.ScreenUpdating = True
End Sub
 
Phil -

I get that error message if the parent worksheet is protected.

You don't need to select the chart to resize it. This works whether or
not the sheet is protected:

Sub GoToMetric1()
Sheets("Metrics").Select
Range("A1").Select
With ActiveSheet.ChartObjects("Chart 13")
.Height = 660
.Width = 780
.Top = 10
.Left = 125
End With
End Sub


- Jon
 
Jon, You are correct - all worksheets in this workbook
are protected. I changed the code to exactly as you have
here. Worksheet "Metrics" does come up, with the cursor
in A1. There are two buttons with the exact same macro
code - the difference being the macro names -
"GoToMetric1" and "GoToMetric2"; and the chart names -
"Chart 13" and "Chart 17" (chart names are correct).
Regardless of which Button is clicked the same chart is
selected. Where am I going wrong?

Thanks, Phil
 
Phil -

And you've changed

With ActiveSheet.ChartObjects("Chart 13")

to

With ActiveSheet.ChartObjects("Chart 17")??

If so, I can't think of a reason this would happen.

- Jon
 
Back
Top