| 12
 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
 
 | 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 l'UserForm
    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 |