patricktoulon
XLDnaute Barbatruc
Bonjour à tous
j'ai un soucis avec la sauvegarde directe d'un object (shape picture, etc..) en WMF sans passer par olecreatepictureindirect
si quelqu'un sait je prends
j'ai un soucis avec la sauvegarde directe d'un object (shape picture, etc..) en WMF sans passer par olecreatepictureindirect
si quelqu'un sait je prends
VB:
Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Private Declare PtrSafe Function GetClipboardData Lib "user32" (ByVal wFormat As LongPtr) As LongPtr
Private Declare PtrSafe Function CopyMetaFileA Lib "gdi32" (ByVal hmf As LongPtr, ByVal lpFileName As String) As LongPtr
Private Declare PtrSafe Function DeleteEnhMetaFile Lib "gdi32" (ByVal hEmf As LongPtr) As Long
Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal Format As Long) As Long
'LA FONCTION POUR LE FORMAT WMF
Function copyObjToWmfFile(obj As Object, Optional cheminX = "")
Dim hMeta As LongPtr, hCopy As LongPtr
If cheminX = "" Then cheminX = ThisWorkbook.Path & "\captureObject.Wmf"
' Copier la shape au format Metafile
OpenClipboard (0): EmptyClipboard: CloseClipboard
obj.CopyPicture
' Récupérer l'image en Metafile dans le presse papier et le sauve vers un fichier
If OpenClipboard(0) Then
Debug.Print "available in clip : " & IsClipboardFormatAvailable(&H3)
If IsClipboardFormatAvailable(&H3) = 0 Then MsgBox " pas de meta dans le clip": Exit Function
hMeta = GetClipboardData(&H3) ' VF_METAFILE = 0x3 (format WMF)soit au format Hex "&H3"
Debug.Print "Handle hMeta : " & hMeta
If hMeta <> 0 Then hCopy = CopyMetaFileA(hMeta, cheminX) ' Copier l'EMF dans un fichier
Debug.Print "hcopy : " & hCopy
DeleteEnhMetaFile hCopy ' Libérer la mémoire
End If
CloseClipboard ' Fermer le presse-papiers
copyObjToWmfFile = cheminX
End Function
Sub TestF()
copyObjToWmfFile ActiveSheet.Shapes("boule"), Environ("userprofile") & "\DeskTop\wmfboule.wmf"
End Sub