1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Option Explicit
#If VBA7 Then
Private Declare ptrsafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
#Else
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Integer) As Long
#End If
Function Copy_All_To_Fichier(obj As Variant, desti As String)
Dim hPicAvail&, i&
With CreateObject("htmlfile").parentwindow.clipboardData.clearData("Text"): End With 'on vide le clipboard entre chaque copie pour tester vraiment le available
Application.ScreenUpdating = False
obj.CopyPicture 'Appearance:=xlScreen, Format:=xlBitmap
Do: i = i + 1: DoEvents: hPicAvail = IsClipboardFormatAvailable(14): Loop While hPicAvail = 0 Or i = 5000
If hPicAvail = 0 Then MsgBox "le clipboard n'a pas d'image": ActiveWorkbook.Close False
Workbooks.Add
With ActiveSheet.ChartObjects.Add(0, 0, obj.Width, obj.Height).Chart
.Paste:
Do: DoEvents: Loop While .Pictures.Count = 0
.Export desti, UCase(Mid(desti, InStrRev(desti, ".") + 1))
End With
ActiveWorkbook.Close False
End Function |
Partager