Macro Copy/Paste error

D

Deorum

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
 
J

Jim Cone

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
 

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