ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Copy/Paste error (https://www.excelbanter.com/excel-programming/418917-macro-copy-paste-error.html)

Deorum

Macro Copy/Paste error
 
I've been handed a piece of code and told to work out why it's
breaking. Basically There is a for loop that copies a range using
CopyPicture, and pastes it into a chart object to finally export the
chart as a JPEG.

What I am getting is an error - 1004 Microsoft Excel cannot paste the
data.

This error will occur at random times and it seems to happen sooner
with more processes running.

I can get through approx x number of iterations, close the book,
repoen and start again from x getting approx the same number of
iterations.

Any Ideas? Thanks in advance...

rngSelection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

' Add a chart object to the activesheet
Set cto = ActiveSheet.ChartObjects.Add(0, 0, 800, 600)
Set cht = cto.Chart

' Paste the picture onto the chart and set an object variable for it
cto.Activate
With cht
ChartArea.Select
.Paste
End With

Jim Cone[_2_]

Macro Copy/Paste error
 
Try adding a dot in front of Chart.Area.Select...
With cht
.ChartArea.Select
.Paste
End With
--
Jim Cone
Portland, Oregon USA



"Deorum"
wrote in message
I've been handed a piece of code and told to work out why it's
breaking. Basically There is a for loop that copies a range using
CopyPicture, and pastes it into a chart object to finally export the
chart as a JPEG.
What I am getting is an error - 1004 Microsoft Excel cannot paste the
data.
This error will occur at random times and it seems to happen sooner
with more processes running.
I can get through approx x number of iterations, close the book,
repoen and start again from x getting approx the same number of
iterations.
Any Ideas? Thanks in advance...

rngSelection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
' Add a chart object to the activesheet
Set cto = ActiveSheet.ChartObjects.Add(0, 0, 800, 600)
Set cht = cto.Chart
' Paste the picture onto the chart and set an object variable for it
cto.Activate
With cht
ChartArea.Select
.Paste
End With


All times are GMT +1. The time now is 02:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com