This will resize the pasted shape according to the longest dimension.
Sub SaveAsGif()
Dim ws As Worksheet
Dim chtHolder As Chart
Dim lngIndex As Long
Set chtHolder = Charts.Add
Do While chtHolder.SeriesCollection.Count > 0
chtHolder.SeriesCollection(1).Delete
Loop
For lngIndex = ActiveWorkbook.Worksheets.Count To 1 Step -1
Set ws = ActiveWorkbook.Worksheets(lngIndex)
If ws.Name <> "Sheet1" Then
ws.Select
ws.Range("A1", ws.Range("B65536").End(xlUp)).CopyPicture Appearance:=xlScreen, Format:=xlBitmap
chtHolder.Select
chtHolder.Paste
' autosize shape
With chtHolder.Shapes(1)
.LockAspectRatio = True
If .Width > .Height Then
.Width = chtHolder.ChartArea.Width
Else
.Height = chtHolder.ChartArea.Height
End If
End With
chtHolder.Export Filename:="C:\temp\" & ws.Name & ".gif", FilterName:="GIF"
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
chtHolder.Shapes(1).Delete
End If
Next
Application.DisplayAlerts = False
chtHolder.Delete
Application.DisplayAlerts = True
End Sub
Bookmarks