Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default copy shape image into image control

I got a sheet with several pictures. Inserted by Insert / Picture / From
File. Now I'm trying to create a VBA userform which shows small-sized
versions of these images. Is there a way of getting an image from a shape
into a userforms image control picture property?
thanks a lot, Luc


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default copy shape image into image control

Hi Luc,
You can test something like:

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(8) As Byte
End Type

Private Type PICTDESC
cbSize As Long
picType As Long
hImage As Long
End Type

Private Declare Function OpenClipboard& Lib _
"user32" (ByVal hwnd&)
Private Declare Function EmptyClipboard& Lib "user32" ()
Private Declare Function GetClipboardData& Lib _
"user32" (ByVal wFormat%)
Private Declare Function SetClipboardData& Lib _
"user32" (ByVal wFormat&, ByVal hMem&)
Private Declare Function CloseClipboard& Lib "user32" ()
Private Declare Function CopyImage& Lib "user32" (ByVal handle& _
, ByVal un1&, ByVal n1&, ByVal n2&, ByVal un2&)
Private Declare Function IIDFromString Lib "ole32" _
(ByVal lpsz As String, ByRef lpiid As GUID) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32" _
(pPictDesc As PICTDESC, ByRef riid As GUID _
, ByVal fOwn As Long, ByRef ppvObj As IPicture) As Long
Private Declare Function DestroyIcon& Lib "user32" (ByVal hIcon&)

' Copy sheet picture to UserForm
Private Sub CommandButton1_Click()
If nbPictures = 0 Then Exit Sub
ThisWorkbook.Sheets(1).Shapes("Picture 1").CopyPicture 1, 2
Call ImageToMePicture
End Sub

Private Function nbPictures() As Integer
nbPictures = ThisWorkbook.Sheets(1).Shapes.Count
If nbPictures = 0 Then MsgBox "Aucune image trouvée !", 64
End Function

Private Sub ImageToMePicture()
Dim hCopy&: OpenClipboard 0&
' Bitmap = 2 / Metafile = 14
hCopy = CopyImage(GetClipboardData(2), 0, 0, 0, &H4)
CloseClipboard
If hCopy = 0 Then Exit Sub
Const IPictureIID = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"
Dim iPic As IPicture, tIID As GUID, tPICTDEST As PICTDESC, Ret&
Ret = IIDFromString(StrConv(IPictureIID, vbUnicode), tIID)
If Ret Then Exit Sub
With tPICTDEST
.cbSize = Len(tPICTDEST)
' Bitmap = 1 / Metafile = 4
.picType = 1
.hImage = hCopy
End With
Ret = OleCreatePictureIndirect(tPICTDEST, tIID, 1, iPic)
If Ret Then Exit Sub
'Me.Picture = LoadPicture("")
'Me.Picture = IPic
Me.Image1.Picture = LoadPicture("")
Me.Image1.Picture = iPic
' Save picture as file (Metafichier - c:\xxx.wmf)
'SavePicture iPic, "c:\xxx.bmp"
Set iPic = Nothing
End Sub

' Copy UserForm picture to sheet
Private Sub CommandButton3_Click()
Dim iPic As StdPicture, hCopy&
'Set iPic = Me.Picture
Set iPic = Me.Image1.Picture
OpenClipboard 0&: EmptyClipboard
hCopy = SetClipboardData(2, iPic.handle)
CloseClipboard
If hCopy Then
ActiveSheet.Cells(1, 1).Select
ActiveSheet.Paste
' Save picture as file (Metafichier - c:\xxx.wmf)
'SavePicture iPic, "c:\xxx.bmp"
End If
DestroyIcon iPic.handle
Set iPic = Nothing
End Sub

MP

"Luc Benninger" <lb (at) zignet.ch a écrit dans le message de
...
I got a sheet with several pictures. Inserted by Insert / Picture / From
File. Now I'm trying to create a VBA userform which shows small-sized
versions of these images. Is there a way of getting an image from a shape
into a userforms image control picture property?
thanks a lot, Luc




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default copy shape image into image control

Thank you Michel Pierron for your code. I had the same problem and i
has been solved pasting your code.

PQill

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink to an image in other worksheet, displaying entire image. twilliams Excel Worksheet Functions 0 February 7th 06 10:02 PM
Trouble with Image Control on a worksheet MChrist Excel Worksheet Functions 0 August 19th 05 01:18 PM
Export the worksheet background image as an image file - possible? DataFreakFromUtah Excel Programming 2 April 10th 04 04:49 PM
Open image from web in window same size as image? Milos Setek Excel Programming 0 February 5th 04 03:33 AM
Click on Image Control disables it Wexler Excel Programming 0 October 7th 03 05:35 PM


All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"