Dave Peterson

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I try to use the script you help me with to copy pictures from one sheet to
another
this one:
Sub testme()
Dim FWks As Worksheet
Dim TWks As Worksheet
Dim myPict As Picture

Set FWks = Worksheets("billeder")
Set TWks = Worksheets("print")

For Each myPict In FWks.Pictures
myPict.copy
TWks.Range(myPict.TopLeftCell.Address(0, 0)).PasteSpecial _
Paste:=xlPasteAll
Next myPict

End Sub
But get an error by excel there write
"excel canoot paste the data"

CAn you or someone else help me?

regards

Alvin
 
See if this works:

Sub testme1()
Dim FWks As Worksheet
Dim TWks As Worksheet
Dim myPict As Object

Set FWks = Worksheets("billeder")
Set TWks = Worksheets("print")

TWks.Select
For Each myPict In FWks.Pictures
If TypeName(myPict) = "Picture" Then
myPict.Copy
TWks.Range(myPict.TopLeftCell.Address(0, 0)).Select
TWks.Paste
End If
Next myPict


End Sub
 
Both Tom's code and my code worked for me (xl2002).

(An aside: I was kind of surprised that .pastespecial worked with the
pictures. Did that change behavior change? I don't recall it working in xl97
that way.)

Are you sure it's not a display problem. Try minimizing excel and resizing.
(or even closing/saving, then reopening your workbook.)
 
Good chance your pictures are not typed as picture.

Put this code in the module

Sub ShowTypename()
msgbox typename(selection)
End Sub

then select one of your pictures and run the macro.

Did it say Picture

If not then try changing this line
If TypeName(myPict) = "Picture" Then

to whatever it said.
 
Sorry sorry sorry to Tom and You
It's because my name on the pictures was
picture 1 picture 2 ans so on
It's working with
picture1 picture2 ans so on

Thanks

Alvin


"Alvin Hansen" skrev:
 
Glad you got it working, but neither versions of the code depended on the names
of the pictures.
 

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

Back
Top