+ Reply to Thread
Results 1 to 4 of 4

Hotkey For Rectangle "Scale Height & Scale Width"

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-16-2020
    Location
    Tehran, Iran
    MS-Off Ver
    2019 v2306
    Posts
    145

    Hotkey For Rectangle "Scale Height & Scale Width"

    Hello
    I need Hotkey for change Scale Height and Scale Width of Rectangle

    VBA code or Macro is awesome


    Thank you in advance for your answer

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,122

    Re: Hotkey For Rectangle "Scale Height & Scale Width"

    Maybe something like this:

    In the ThisWorkbook code

    Private Sub Workbook_Activate()
    Call assign(True)
    End Sub
    
    Private Sub Workbook_Open()
    Call assign(False)
    End Sub

    Then in a standard module
    Ctrl+arrows will then scale the shape according to the constants.

    Sub assign(OnOff As Boolean)
    Const L As Single = 0.2
    Const R As Single = 1.2
    Const D As Single = 1.2
    Const U As Single = 0.2
    
    With Application
        If OnOff Then
            .OnKey "^{LEFT}", "'ScaleShape " & L & "," & """LR""" & "'"
            .OnKey "^{RIGHT}", "'ScaleShape " & R & "," & """LR""" & "'"
            .OnKey "^{UP}", "'ScaleShape " & U & "," & """UD""" & "'"
            .OnKey "^{DOWN}", "'ScaleShape " & D & "," & """UD""" & "'"
        Else
            .OnKey "^{LEFT}", ""
            .OnKey "^{RIGHT}", ""
            .OnKey "^{UP}", ""
            .OnKey "^{DOWN}", ""
        End If
    End With
    End Sub
    
    
    Sub ScaleShape(v As Single, Which$)
    Dim shp As Shape
    If TypeName(Selection) = "Rectangle" Then
        Set shp = ActiveSheet.Shapes(Selection.Name)
        With shp
            .LockAspectRatio = msoFalse
            Select Case Which
                Case "LR"
                    .ScaleWidth v, msoFalse
                Case "UD"
                    .ScaleHeight v, msoFalse
            End Select
            .LockAspectRatio = msoTrue
        End With
    End If
    End Sub

  3. #3
    Forum Contributor
    Join Date
    04-16-2020
    Location
    Tehran, Iran
    MS-Off Ver
    2019 v2306
    Posts
    145

    Re: Hotkey For Rectangle "Scale Height & Scale Width"

    Hello
    Thanks for your time

    I puted codes in VBA and save it as .xlsm but I didn't see change
    could you please put the code in attach file

    I need hotkey for change scale in percentage


    I really appreciate of you
    Attached Files Attached Files

  4. #4
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,122

    Re: Hotkey For Rectangle "Scale Height & Scale Width"

    Try these changes

    Sub assign(OnOff As Boolean)
    With Application
        If OnOff Then
            .OnKey "^{UP}", "'ScaleShape " & """UP""" & "'"
            .OnKey "^{DOWN}", "'ScaleShape " & """DN""" & "'"
        Else
            .OnKey "^{UP}", ""
            .OnKey "^{DOWN}", ""
        End If
    End With
    End Sub

    Sub ScaleShape(Which$)
    Dim shp As Shape
    Dim Factor As Single
    If TypeName(Selection) = "Rectangle" Then
        Set shp = ActiveSheet.Shapes(Selection.Name)
        If Which = "UP" Then
            Factor = 1.6
        Else
            Factor = 0.6
        End If
        With shp
            .Height = .Height * Factor
            .Width = .Width * Factor
        End With
    End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 04-24-2020, 02:41 AM
  2. [SOLVED] 2 axis scale using INDEX, SUMPRODUCT, and "greater than" and "less than" functions
    By Clooney003 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-20-2017, 01:12 PM
  3. "Scale to fill out" instead of "Scale to fit"?
    By lbickford in forum Excel General
    Replies: 1
    Last Post: 07-26-2017, 02:14 PM
  4. Replies: 8
    Last Post: 11-16-2016, 05:58 PM
  5. Excel 2007 : 3 color Scale - Ignore "0" values
    By micahblouin in forum Excel General
    Replies: 5
    Last Post: 05-10-2011, 03:37 PM
  6. [SOLVED] Do mighty exchange "pixels" on "mm" - cells (width, height)? :(
    By And1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2006, 08:15 AM
  7. "Scale breaks" required in (Z) axis
    By FH1 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-04-2005, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1