View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default How to copy a drawing image between sheets

Your code worked fine for me.

What line caused the mismatch error?

Sarah (OGI) wrote:

Dave

I've tried using this code through a copy/paste, and also by typing it out
from scratch, but both ways result in a run-time error 13, Type Mismatch.
The code being used should match what had previously been suggested:

==========
Sub CopyAllPictures()

Dim r As Long, c As Long
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim pic As Picture

Set wsSource = Worksheets("Sheet1")
Set wsDest = Worksheets("Sheet2")

r = wsSource.Rows.Count
c = wsSource.Columns.Count

For Each pic In wsSource.Pictures
With pic.TopLeftCell
If .Row < r Then r = .Row
If .Column < c Then c = .Column
End With
Next

wsDest.Activate
wsDest.Cells(r, c).Activate

wsSource.Pictures.Copy
wsDest.Paste

wsDest.Cells(r, c).Activate

End Sub
=======

Not sure why its not working?

"Dave Peterson" wrote:

Either you changed the code (it worked fine for me) or something bad got
included when you did the copy|paste.

If you changed the code, post your current version.

If you pasted the code, then try deleting that line and just retype that "next"
line.

(Sometimes, copying from a window on the web can get you some extra characters.)

Sarah (OGI) wrote:

I have a similar request to that posed in this thread and I have used the
code identified below to copy all pictures.

However, I am getting a Type Mismatch error when running it. On debug, the
system highlights the word "Next".

Am I missing something?

Thanks
Sarah

"Peter T" wrote:

Hi Clara,

It's not clear if you want to copy individual pictures or all pictures from
one sheet to another. Here's a pair of macros to do both -

Sub CopyAllPictures()
Dim r As Long, c As Long
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim pic As Picture

Set wsSource = Worksheets("Sheet1")
Set wsDest = Worksheets("Sheet2")

r = wsSource.Rows.Count
c = wsSource.Columns.Count

For Each pic In wsSource.Pictures
With pic.TopLeftCell
If .Row < r Then r = .Row
If .Column < c Then c = .Column
End With
Next

wsDest.Activate
wsDest.Cells(r, c).Activate

wsSource.Pictures.Copy
wsDest.Paste

wsDest.Cells(r, c).Activate

End Sub

Sub CopyOnePicture()
Dim wsSource As Worksheet
Dim wsDest As Worksheet

Set wsSource = Worksheets("Sheet1")
Set wsDest = Worksheets("Sheet2")

Set pic = wsSource.Pictures("Picture 1")

pic.Copy
wsDest.Paste

With wsDest.Pictures(wsDest.Pictures.Count)
.Left = pic.Left
.Top = pic.Top
End With

End Sub

Regards,
Peter T

"clara" wrote in message
...
Hi all

while copying data, I want to copy images between sheets. How can I do it?


Clara

thank you so much for your help




--

Dave Peterson


--

Dave Peterson