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
| Sub SavePictureAs(strPicName As String, ByVal strFile As String, strFormat As String)
Dim wsTemp As Worksheet, chtObj As Chart, pObj As Picture
Dim dblWidth As Double, dblHeight As Double
ActiveSheet.Shapes(strPicName).Select
Set pObj = Selection
dblWidth = pObj.Width: dblHeight = pObj.Height: pObj.Copy
Application.ScreenUpdating = False
Set chtObj = Charts.Add: Set wsTemp = Sheets.Add
chtObj.Location Where:=xlLocationAsObject, Name:=wsTemp.Name
wsTemp.Range("A1").Select
With wsTemp.ChartObjects(1)
.Top = 0
.Left = 0
.Width = dblWidth
.Height = dblHeight
.Activate
.Chart.Paste
.Interior.ColorIndex = 1
.Chart.Export Filename:=strFile, FilterName:=strFormat
End With
Application.DisplayAlerts = False: wsTemp.Delete
Application.DisplayAlerts = True: Application.ScreenUpdating = True
End Sub |
Partager