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
| Public Function ExporterPlageCommeImage(PlageAExporter As Range)
On Error GoTo FonctionErreur
'cacher ou afficher les lignes de grille
ActiveWindow.DisplayGridlines = False ' or True
'Copier la PlageAExporter comme image dans le Presse-papier
PlageAExporter.CopyPicture Appearance:=xlScreen, Format:=xlPicture
'Créer un nouveau "graphique" temporaire qui servira de support - avec la taille exacte de la plage à exporter
With ActiveSheet.ChartObjects.Add(Left:=PlageAExporter.Left, Top:=PlageAExporter.Top, _
Width:=PlageAExporter.Width, Height:=PlageAExporter.Height)
.Name = "ExportImage"
.Activate
End With
'Copier l'image dans le graphique, ouvrir le dialog de "Sauvegarder sous", sauvegarde le fichier et supprime le graphique temporaire
ActiveChart.Paste
FichierImage = Application.GetSaveAsFilename(InitialFileName:="*.jpg", FileFilter:="Image file (*.jpg), *.jpg")
If FichierImage = False Then Exit Function
ActiveSheet.ChartObjects("ExportImage").Chart.Export FichierImage
ActiveSheet.ChartObjects("ExportImage").Delete
Exit Function
FonctionErreur:
MsgBox "Une erreur est survenue..."
End Function
Sub test()
ExporterPlageCommeImage (ActiveSheet.UsedRange)
End Sub |
Partager