Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwflags As Long, ByVal dwExtraInfo As Long)
Sub SaveScreen()
Dim Ws As Worksheet
'Copie d'écran de la forme active par simulation de la touche
keybd_event vbKeySnapshot, 1, 0&, 0&: DoEvents '!
'Ajoute une feuille pour coller l'image
Set Ws = Sheets.Add: Ws.Paste
'impression de la feuille avec image
'With Ws.PageSetup
' .Zoom = False 'si true FitToPagesTall invalide
' .Orientation = xlLandscape
' .CenterHorizontally = True
' .CenterVertically = True
' .FitToPagesTall = 1 'impose sur la hauteur de la page
' .FitToPagesWide = 1 'impose sur la largeur de la page
'End With
'Ws.Application.Dialogs(xlDialogPrint).Show
'save l'écran sur disque
'il copy d'abord l'objet pour le sauver
Dim Pict As Picture
For Each Pict In ActiveSheet.Pictures
'MsgBox Pict.Name
Pict.CopyPicture xlScreen, xlBitmap
With ActiveSheet.ChartObjects.Add(0, 0, Pict.Width, Pict.Height).Chart
.Paste
.Export "E:\" & Pict.Name & ".gif", "GIF" 'ou ".jpg", "JPG"
End With
X = ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(X).Delete 'efface le dernier
Next
End Sub