exporting excel images to files

Sub ExportMyPicture()

Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False
On Error GoTo Finish

MyPicture = Selection.Name
With Selection
PicHeight = .ShapeRange.Height + 8
PicWidth = .ShapeRange.Width + 8
End With

Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=”Sheet1″
Selection.Border.LineStyle = 0
MyChart = Selection.Name & ” ” & Split(ActiveChart.Name, ” “)(2)

With ActiveSheet
With .Shapes(MyChart)
.Width = PicWidth
.Height = PicHeight
End With

.Shapes(MyPicture).Copy

With ActiveChart
.ChartArea.Select
.Paste
End With

.ChartObjects(1).Chart.Export Filename:=”MyPic.jpg”, FilterName:=”jpg”
.Shapes(MyChart).Cut
End With

Application.ScreenUpdating = True
Exit Sub

Finish:
MsgBox “You must select a picture”
End Sub

Leave a comment