Option Explicit
Private Const Fichier As String = "C:\ImageTemp.gif"
Private Sub CommandButton1_Click()
Dim nb As Byte
Dim Sh As Shape
'Supprime l'image temportaire si elle existe
If Dir(Fichier) <> "" Then Kill Fichier
'Définit le 1er shape de la feuille comme image
' à afficher dans l'UserForm
Set Sh = Worksheets("Feuil1").Shapes(1)
'copie le shape dans la feuille
Sh.CopyPicture
'crée un graphique
With ActiveSheet.ChartObjects.Add(0, 0, _
Sh.Width, Sh.Height).Chart
.Paste 'colle l'image dans graphique
' enregistre le graphique au format gif
.Export Fichier, "GIF"
End With
nb = ActiveSheet.ChartObjects.Count
'supprime le graphique
ActiveSheet.ChartObjects(nb).Delete
'Affiche l'image dans le graphique
Image1.Picture = LoadPicture(Fichier)
End Sub
Private Sub UserForm_Terminate()
'Supprime l'image temportaire si elle existe
If Dir(Fichier) <> "" Then Kill Fichier
End Sub