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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| '*****************************************************************************************************
' ___ _ _______ __ _ ____ _ _ _______ ___ _ _ _ ___ _ _.
' // \\ /\\ // // \\ // // // // // // \\ // // // // \\ //| //
' //___// //__\ // //__// // // //__// // // // // // // // // // | //
' // // \\ // // \\ // // // \\ // // // // // // // // // | //
'// // // // // // // //___ // \\ // \\__// //__// //___ \\__// // |//
'****************************************************************************************************
' COLLECTION IMAGE ET SHAPES
'exporter un object en PNG(range,shapes et tout autre object present sur la feuille)
'version avec graphique 1.3(PNG)
'date version 03/05/2016
'***********************************************************
'Cette version donne l'avantage de garder la transparence *
'Et semie transparence pour les shapes ou picture *
'***********************************************************
'mise à jour:15/07/2018
'suppression de la gestion d'attente par l'api IsClipboardFormatAvailable
'remplacer par un multiple paste dans le chart dans que son pictures.count=0(Idée de @Job75)
'l'area du graph est visible ,solid et transparent à 100%
'mise à jour:03/05/2024
'modification du switch transparence
'**********************************************************************************
Option Explicit
Dim cheminT$
Function CopyOBJECTInImagePNG(ObjectOrRange, _
Optional cheminx As String = "", _
Optional transparency As Boolean = True) As String
Dim Graph As Object
If cheminx = "" Then cheminx = ThisWorkbook.Path & "\imagetemp.png" 'path du fichier par defaut
With CreateObject("htmlfile").parentwindow.clipboardData.clearData("Text") 'on vide le clipboard entre chaque copie pour tester vraiment le available
End With
ObjectOrRange.CopyPicture 'Format:=IIf(Notransparency, xlBitmap, xlPicture)
Set Graph = ObjectOrRange.Parent.ChartObjects.Add(0, 0, 0, 0).Chart
Graph.Parent.ShapeRange.Line.Visible = msoFalse
With Graph.Parent
.Width = ObjectOrRange.Width: .Height = ObjectOrRange.Height: .Left = ObjectOrRange.Width + 20:
.Select
Do: DoEvents: .Chart.Paste: Loop While .Chart.Pictures.Count = 0
With .Chart
.ChartArea.Fill.Visible = msoTrue
.ChartArea.Fill.Solid
If transparency Then
.ChartArea.Format.Fill.transparency = 1
Else
.ChartArea.Format.Fill.transparency = 0.01
End If
.Export cheminx, Split(cheminx, ".")(1)
End With
End With
Graph.Parent.Delete
CopyOBJECTInImagePNG = cheminx
End Function
'***************************************************
'sub de test
Sub export_Range_To_ImagePNG()
Dim Fichier$
Fichier = ThisWorkbook.Path & "\imagetemp.png"
CopyOBJECTInImagePNG [Feuil1!A1:F10], Fichier
End Sub
'sub de test
Sub export_Range_To_ImagePNGNOtransparency()
Dim Fichier$
Fichier = ThisWorkbook.Path & "\imagetemp.png"
CopyOBJECTInImagePNG [Feuil1!A1:F10], Fichier, False
End Sub
'***************************************************
Sub export_boite_To_ImagePNGNotransparency()
Dim Fichier$
Fichier = ThisWorkbook.Path & "\" & ActiveSheet.Shapes("boite").Name & ".png"
CopyOBJECTInImagePNG ActiveSheet.Shapes("boite"), Fichier
End Sub
Sub export_Object_To_ImagePNGtransparency()
Dim Fichier$
Fichier = ThisWorkbook.Path & "\" & ActiveSheet.Shapes("Boule").Name & ".png"
CopyOBJECTInImagePNG ActiveSheet.Shapes("Boule"), Fichier, True
End Sub |
Partager