PDA

Click to See Complete Forum and Search --> : Resize Chart in Proportion [RESOLVED]


agmorgan
May 13th, 2004, 05:38 AM
Im having the same problem as this guy.
http://www.vbforums.com/showthread.php?s=&threadid=200467&highlight=chart+resize

I dont want my plot of a circle to change to an ellipse when I resize my chart.

The code to do it in VBA is ActiveSheet.Shapes("Chart 1").ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 1").ScaleHeight 0.88, msoFalse, msoScaleFromTopLeft This resizes by 0.8 and keeps the proportions.
I got this by recording a macro whilst holding down shift and resizing.

What I am trying to do, is have a worksheet event that ONLY allows proportional resizing.

ie when I resize the chart, it always gives the effect of shift being held down at the same time

agmorgan
May 13th, 2004, 09:54 AM
With a bit (well actually a lot :)) of digging I came up with this solution.

Follow the instruction on KB213738
http://support.microsoft.com/default.aspx?scid=kb;en-us;213738

Basically, add this to a classOption Explicit

Public WithEvents EmbChart As Chart


Private Sub EmbChart_Resize()
Dim strWidth As String
Dim strHeight As String

strWidth = ActiveSheet.Shapes("Chart 1").Width
ActiveSheet.Shapes("Chart 1").Height = strWidth

End Sub
And this in the ThisWorkbook module Option Explicit

Dim clsChart As New clsEvent


Private Sub Workbook_Open()
Set clsChart.EmbChart = Sheet1.ChartObjects(1).Chart
End Sub


Voila!
The height is always the same as the width!!