chartobjects.activate fails

S

Scooter

I have the following snipet in my code

Windows("abc.xls").Activate
Sheets("Profile").Select
ActiveSheet.ChartObjects(1).Activate

When I get to the 3rd line I get a "runtime error 1004". I have verified
that the sheet does contain a chart. I have used this in other workbooks
with no problem. What is wrong here?
 
J

Jacob Skaria

Try replacing the index with chart name.

ActiveSheet.ChartObjects("ChartName").Activate

Jacob
 
J

Jon Peltier

Is the sheet (or chart) protected? Is it the active sheet? Is the chart on a
sheet that's grouped with another sheet, or in a workbook that is shared?

- Jon
 
S

Scooter

The sheet is not protected. Yes the chart is on the active sheet. The sheet
is not part of a group or shared workbook. This is very strange to me since
I have used this code many times but for this one instance it does not work.
 
J

Jon Peltier

Could be a corrupted workbook, to use a trite excuse.

Do you realize that you don't need to do all the activating and selecting
just to modify something in the chart? If your next line of code is (for
example)

ActiveChart.HasTitle = True

you can achieve the same using

Workbooks("abc.xls").Worksheets("Profile").ChartObjects(1).Chart.HasTitle
= True

- Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top