1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| #If win64 Then 'si windows 64
#If VBA7 Then 'si excel 64 dans windows 64
Private Declare ptrsafe Function CloseClipboard Lib "user32" () As Long
Private Declare ptrsafe Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare ptrsafe Function GetClipboardData Lib "user32" (ByVal uFormat As Long) As Long
Private Declare ptrsafe Function CopyEnhMetaFileA Lib "gdi32" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
Private Declare ptrsafe Function DeleteEnhMetaFile Lib "gdi32" (ByVal hDC As Long) As Long
#Else 'si excel 32 dans windows 64
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal uFormat As Long) As Long
Private Declare Function CopyEnhMetaFileA Lib "gdi32" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
Private Declare Function DeleteEnhMetaFile Lib "gdi32" (ByVal hDC As Long) As Long
#End If
#Else 'si windows 32 et excel 32
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal uFormat As Long) As Long
Private Declare Function CopyEnhMetaFileA Lib "gdi32" (ByVal hemfSrc As Long, ByVal lpszFile As String) As Long
Private Declare Function DeleteEnhMetaFile Lib "gdi32" (ByVal hDC As Long) As Long
#End If
Private Sub CommandButton1_Click()
Set cel = Sheets("Base de donnée").Range("A:A").Find(UCase(TextBox1.Text), lookat:=xlWhole)
If Not cel Is Nothing Then
For Each SHAP In Sheets("Base de donnée").Shapes
If SHAP.TopLeftCell.Row = cel.Row Then CopiePhoto SHAP
Next
End If
End Sub
Sub test()
End Sub
Sub CopiePhoto(Source)
Dim FicTmp As String
'FicTmp = Environ("userprofile") & "\DeskTop\image.wmf"
'ou
With CreateObject("WScript.Shell"): FicTmp = .SpecialFolders("Desktop") & "\image.wmf": End With
'
Source.CopyPicture
OpenClipboard 0: DeleteEnhMetaFile CopyEnhMetaFileA(GetClipboardData(14), FicTmp): CloseClipboard
If Dir(FicTmp) <> "" Then Image1.Picture = LoadPicture(FicTmp)
Kill FicTmp
End Sub |
Partager