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
| Public Function ExporterPlageCommeImage(PlageAExporter As Range, LignesDeGrille As Boolean, nomfeuille As String)
On Error GoTo FonctionErreur
Application.ScreenUpdating = False
'cacher ou afficher les lignes de grille
ActiveWindow.DisplayGridlines = LignesDeGrille
'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
ActiveSheet.ChartObjects("ExportImage").Chart.Export ThisWorkbook.Path & "\" & nomfeuille & ".jpg" 'FichierImage
ActiveSheet.ChartObjects("ExportImage").Delete
Application.ScreenUpdating = True
Exit Function
FonctionErreur:
Application.ScreenUpdating = True
MsgBox "Une erreur est survenue..."
End Function
Sub test()
Dim NomComplet As String
NomComplet = Range("L9").Value
If InStr(Selection.Address, ",") > 0 Then
tempo = Left(Selection.Address, InStr(Selection.Address, ",") - 1)
Else
tempo = Selection.Address
End If
Select Case MsgBox("Afficher le quadrillage ?", vbYesNo, "Information !")
Case vbYes
ExporterPlageCommeImage Range(tempo), True, NomComplet
Case vbNo
ExporterPlageCommeImage Range(tempo), False, NomComplet
End Select
End Sub |
Partager