VBA + Charts = INSANITY

John McGraw

Board Regular
Joined
Feb 25, 2002
Messages
76
Why do I have so much trouble trying to code embedded charts in VBA????

Right now I am trying to paste a chart as a picture in order to create a "dead chart". So to get some ideas, I recorded the following macro:<pre/>

Sub Macro2()
'
' Macro2 Macro
' Macro recorded 04/25/2002 by John A. McGraw
'
'
Range("A1:A10").Select
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A10")
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
ActiveChart.ChartArea.Copy
ActiveChart.Pictures.Paste.Select
End Sub</pre>

The crazy thing is, this works in realtime... But if I run this macro I GET ERRORS! I almost cant believe it.

This is the run-time error:<pre/>

Run-time error '1004':
Method 'ChartArea' of object '_Chart' failed</pre>

Now I come across these errors when I write chart code myself, but this is the first time it
happened with code written by the macro-recorder.

If anyone knows a way to turn a chart into a picture in VBA code, please let me know.

Note: To "paste as picture" in realtime, I select the edit menu while holding down the shift key.
This message was edited by John McGraw on 2002-04-25 14:39
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,214,520
Messages
6,120,017
Members
448,937
Latest member
BeerMan23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top