Graph Re-size Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to be able to create a button that will automatically enlarge a graph,
and then when it is pushed again will shrink the graph back to its original
size. I tried doing this and the graph kept shifting to the left every time
I pressed the button. I do not want the graph to move, only to resize.

Thanks

Adam Bush
 
If you want suggestions on your existing code, you should post it.

How about changing the window zoom instead of messing with the chart?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"(e-mail address removed)"
 
Jon,

Thanks for the reply. Here is the code for enlarging the graphs:

ActiveSheet.ChartObjects("Chart 357").Activate
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 357").ScaleWidth 1.36, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 357").ScaleHeight 2.4, msoFalse, _
msoScaleFromBottomRight
ActiveWindow.Visible = False
Windows("Everything Regression Prototype.xls").Activate
ActiveSheet.ChartObjects("Chart 358").Activate
ActiveChart.Axes(xlValue).Select
ActiveChart.Legend.Select
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 358").ScaleWidth 1.18, msoFalse,
msoScaleFromTopLeft
ActiveSheet.Shapes("Chart 358").ScaleHeight 2.4, msoFalse, _
msoScaleFromBottomRight

And here is the code for shrinking the graphs:


ActiveSheet.ChartObjects("Chart 357").Activate
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 357").ScaleWidth 0.58, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 357").ScaleHeight 0.36, msoFalse, _
msoScaleFromBottomRight
ActiveWindow.Visible = False
Windows("Everything Regression Prototype.xls").Activate
ActiveSheet.ChartObjects("Chart 358").Activate
ActiveChart.ChartTitle.Select
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 358").ScaleWidth 0.73, msoFalse, _
msoScaleFromBottomRight
ActiveSheet.Shapes("Chart 358").ScaleHeight 0.44, msoFalse, _
msoScaleFromBottomRight

All I did was record a macro and then drag the corner of the graohs to
resize them. I have a feeling the problem has to do with Scaling from the
bottom right in the code. How would I change the window zoom? The key here
is I need to be able to do this through the push of a button.

Thanks

Adam Bush
 
Push of a button is no big deal.

I find it better to change the dimensions of a chart explicitly, rather than
scaling its dimensions. Select the chart and run either of these procedures:

Const dScale as Double = 2.4

Sub ChartExpand()
With ActiveChart.Parent
.Height = .Height * dScale
.Width = .Width * dScale
End With
End Sub

Sub ChartShrink()
With ActiveChart.Parent
.Height = .Height / dScale
.Width = .Width / dScale
End With
End Sub

To change the window zoom:

Sub WindowZoomIn()
ActiveWindow.Zoom = ActiveWindow.Zoom * 2
End Sub

Sub WindowZoomOut()
ActiveWindow.Zoom = ActiveWindow.Zoom / 2
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"(e-mail address removed)"
 
Jon,

Thanks a lot for your help.

Adam Bush

Jon Peltier said:
Push of a button is no big deal.

I find it better to change the dimensions of a chart explicitly, rather than
scaling its dimensions. Select the chart and run either of these procedures:

Const dScale as Double = 2.4

Sub ChartExpand()
With ActiveChart.Parent
.Height = .Height * dScale
.Width = .Width * dScale
End With
End Sub

Sub ChartShrink()
With ActiveChart.Parent
.Height = .Height / dScale
.Width = .Width / dScale
End With
End Sub

To change the window zoom:

Sub WindowZoomIn()
ActiveWindow.Zoom = ActiveWindow.Zoom * 2
End Sub

Sub WindowZoomOut()
ActiveWindow.Zoom = ActiveWindow.Zoom / 2
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"(e-mail address removed)"
 
Back
Top