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
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