Copy picture from image control

I

Ian

I have an Excel addin that contains an image control on a userform. When
the addin is run, I would like to copy the picture from the image control to
a worksheet. What I would like to do is ActiveSheet.pictures.add
Image1.Picture, but of course this doesn't work.

Any suggestions?
 
T

Tom Ogilvy

Where did the image control get the picture - it is usually from a file -
couldn't you import the image from the file?
 
M

Michel Pierron

Hi ,
May be:

Private Declare Function OpenClipboard& _
Lib "user32" (ByVal hwnd As Long)
Private Declare Function EmptyClipboard _
Lib "user32" () As Long
Private Declare Function SetClipboardData& _
Lib "user32" (ByVal wFormat&, ByVal hMem&)
Private Declare Function CloseClipboard& _
Lib "user32" ()
Private Declare Function DestroyIcon& _
Lib "user32" (ByVal hIcon&)

Sub ImageCopy()
Dim iPic As StdPicture, hCopy&
Set iPic = UserForm1.Image1.Picture
OpenClipboard 0&: EmptyClipboard
hCopy = SetClipboardData(2, iPic.handle)
CloseClipboard
If hCopy Then
ActiveSheet.Cells(1, 1).Select
ActiveSheet.Paste
' Save image on disk:
'SavePicture iPic, "c:\Recup.bmp"
End If
DestroyIcon iPic.handle
Set iPic = Nothing
End Sub

Regards,
MP
 
I

Ian

Yes, but then I would need to distribute the file with the addin, which I
don't want to do.
 

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