Skip to content

Instantly share code, notes, and snippets.

@mjdescy
Last active April 9, 2020 14:41
Show Gist options
  • Save mjdescy/879c88bbf0d8295b2ec5803a788e07b1 to your computer and use it in GitHub Desktop.
Save mjdescy/879c88bbf0d8295b2ec5803a788e07b1 to your computer and use it in GitHub Desktop.
Excel macro for setting the selected chart to a default size
Option Explicit
Const DefaultChartHeightInInches As Double = 4#
Const DefaultChartWidthInInches As Double = 8.3
Public Sub SetActiveChartToStandardSize()
If ActiveChart Is Nothing Then
Exit Sub
End If
Call SetChartSize( _
Chart:=ActiveChart, _
Height:=ConvertInchesToPoints(DefaultChartHeightInInches), _
Width:=ConvertInchesToPoints(DefaultChartWidthInInches))
End Sub
Private Sub SetChartSize(ByRef Chart As Excel.Chart, ByVal Height As Double, ByVal Width As Double)
Chart.Parent.Height = Height
Chart.Parent.Width = Width
End Sub
Private Function ConvertInchesToPoints(ByVal Inches As Double) As Double
ConvertInchesToPoints = Round(Inches * 72, 1)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment