Shape Size Scaling Code

Started by Scott10284, April 15, 2020, 12:56:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Scott10284

I would like to create a VBA macro that will automatically scale the selected shape's size when I run the macro. I want to be able to select any shape, run the macro, and the outcome should be that the shape's Height and Width are scaled down by 50% ( so Width*0.5 and Height*0.5 ).

What I ultimately want to do is create a button on my rubbon to execute the macro for ease of use.

Any suggestion on VBA code to accomplish this would be very much appreciated.

Hey Ken

Scott:

   Unless I'm missing something, it seems pretty straightforward.  Here's one approach:



Sub MakeItHalfTheSize()

With ActiveWindow
    If .Selection.Count <> 1 Then
        MsgBox "Please select a shape first."
    Else
        .Selection(1).Cells("Width").Formula = .Selection(1).Cells("Width").Result(0) * 0.5
        .Selection(1).Cells("Height").Formula = .Selection(1).Cells("Height").Result(0) * 0.5
        End If
    End With
   
End Sub



   Just select a shape and run the macro.

   Hope this helps,

   - Ken

Ken V. Krawchuk
Author
No Dogs on Mars - A Starship Story
http://astarshipstory.com

vojo

macro looks great!!

or use the size and position window  (it accepts math equations as well)

width = <current width> *0.5 + 10mm

BTW, you could even set up shape with action bars to decrement or increment

macro  grow = increase shape by 10%
Actions.grow = <call macro grow>

macro shrink = decrease by 10%
actions.shrink = <call macro shrink>

or even a generalized macros to shrink or grow 10%.....pick shape and click macro of interest