Print a Chart worksheet

M

miek

I have the following code that falls on it face.
The chart gets built like:

Charts.Add
ActiveChart.ChartType = xlColumnClustered
....
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:="MyChart"

When I try to print with the below code I recieve a Run-time error 1004
"unable to get the chartobject propertyof the ws class" on the .Activate line

ActiveSheet.ChartObjects("MyChart").Activate
ActiveSheet.PrintOut

Thanks for your help
 
J

Joel

Check to make sure the Chart Sheet Tab on the bottom of the sheet matches the
code. Excel renames charts after the Adds statement.

A chart has one name when its created with the ADD and then changes names
when the location statment is executed. I've seen this happen with excel
2003.
 
M

miek

I right clicked on the WS tab and copied the tab name and placed this value
in the:
ActiveSheet.ChartObjects("MyChart").Activate code line
 
J

Joel

Did it Work?

The statement
ActiveSheet.ChartObjects("MyChart").Activate

Is not needed to print the chart. You are printing a sheet
(ActiveSheet.PrintOut) not the object on the sheet. To find the name of the
Chart Object Manually Activate the chart with the mouse and look at the box
left of the f(x).
 
M

miek

No, I get the same results

Joel said:
Did it Work?

The statement
ActiveSheet.ChartObjects("MyChart").Activate

Is not needed to print the chart. You are printing a sheet
(ActiveSheet.PrintOut) not the object on the sheet. To find the name of the
Chart Object Manually Activate the chart with the mouse and look at the box
left of the f(x).
 
M

miek

I've also tried:
Worksheets("MyChart").ChartObjects.Activate
I get "run-time error 9, subscript out of range"
 
J

Joel

I did some testing. when yo place a Chart on a New Sheet there is no
Chartobject. Remove the line! You only get chart objects when a chart is
placed on a worksheet, not on a sheet by itself.
 
M

miek

If I have the code line:
Worksheets("A1 sum Chart").Activate
I get: "run-time error 9, subscript out of range"
 
J

Joel

There is a different between sheets and worksheets. Worksheets are only
formula sheets. Sheets include Formulas sheets and graphs

Sheets("A1 sum Chart").Activate
 

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