Last active
April 9, 2020 14:41
-
-
Save mjdescy/879c88bbf0d8295b2ec5803a788e07b1 to your computer and use it in GitHub Desktop.
Excel macro for setting the selected chart to a default size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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