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
| Sub essai_dessin()
Dim chO As ChartObject
Dim sh As Worksheet, Obj As Shape
Dim Tableau() As Variant
Dim i As Integer
Dim num_obj As Integer
i = 0
Set sh = Worksheets(1)
For Each Obj In sh.Shapes 'on recense toutes les formes de la feuille
If Obj.Name <> "Commandbutton1" Then 'on exclu la forme bouton de l'image final
i = i + 1
'Redéfinit la taille du tableau et intègre le nom de la forme.
ReDim Preserve Tableau(1 To i)
Tableau(i) = Obj.Name
End If
Next
'On retient le nombre de formes
num_obj = i
'on creer la carte en jpg
Set chO = Sheets(1).ChartObjects.Add(0, 0, 350, 310) 'taille arbitraire
For i = 1 To num_obj
sh.Shapes(Tableau(i)).Copy
chO.Chart.Paste
chO.Chart.Export "C:\truc.jpg", "JPEG"
Next
chO.Delete
End Sub |
Partager