Consulting

Results 1 to 2 of 2

Thread: Increase and decrease shape text margins with limit

  1. #1

    Increase and decrease shape text margins with limit

    Hello everyone. First of all thanks for the support. You are great!

    I know I'm probably making a really dumb mistake in my code but I can't make it out.

    There are three Subs: 1) increase the margin up to a size of 1,5cm; 2) decrease; and 3) reset margins to 0.

    The increase works but ignores de the 1,5 cm limiter. Same happens with the decrease which ignores the 0 limit. The reset works fine.

    Thanks in advance for your help!

    Option Explicit
    Const MarginMax = 28.35 * 1#
    Const MarginIncrement = 28.35 * 0.05
    
    
    Sub marginincrease()
    Dim oshp As Shape
    For Each oshp In ActiveWindow.Selection.ShapeRange
    If oshp.HasTextFrame Then
    With oshp.TextFrame
        If .MarginBottom >= 0 Or .MarginBottom <= MarginMax Then .MarginBottom = .MarginBottom + MarginIncrement
        If .MarginLeft >= 0 Or .MarginLeft <= MarginMax Then .MarginLeft = .MarginLeft + MarginIncrement
        If .MarginTop >= 0 Or .MarginTop <= MarginMax Then .MarginTop = .MarginTop + MarginIncrement
        If .MarginRight >= 0 Or .MarginRight <= MarginMax Then .MarginRight = .MarginRight + MarginIncrement
    End With
    End If
    Next
    End Sub
    
    
    Sub margindecrease()
    Dim oshp As Shape
    For Each oshp In ActiveWindow.Selection.ShapeRange
    If oshp.HasTextFrame Then
    With oshp.TextFrame
        If .MarginBottom >= 0 Or .MarginBottom <= MarginMax Then .MarginBottom = .MarginBottom - MarginIncrement
        If .MarginLeft >= 0 Or .MarginLeft <= MarginMax Then .MarginLeft = .MarginLeft - MarginIncrement
        If .MarginTop >= 0 Or .MarginTop <= MarginMax Then .MarginTop = .MarginTop - MarginIncrement
        If .MarginRight >= 0 Or .MarginRight <= MarginMax Then .MarginRight = .MarginRight - MarginIncrement
    End With
    End If
    Next
    End Sub
    
    
    Sub noMargins()
    Dim oshp As Shape
    For Each oshp In ActiveWindow.Selection.ShapeRange
    If oshp.HasTextFrame Then
    With oshp.TextFrame
        .MarginBottom = 0
        .MarginLeft = 0
        .MarginTop = 0
        .MarginRight = 0
    End With
    End If
    Next
    End Sub

  2. #2
    I was right is was a dumb mistake. Here is the updated code.

    Option Explicit
    Const MarginMax = 28.35 * 1.5
    Const MarginIncrement = 28.35 * 0.05
    
    
    Sub MarginIncrease()
    Dim oShape As Shape
    
    
    For Each oShape In ActiveWindow.Selection.ShapeRange
        If oShape.HasTextFrame Then
        With oShape.TextFrame
            If (.MarginBottom + MarginIncrement) <= MarginMax Then .MarginBottom = (.MarginBottom + MarginIncrement)
            If (.MarginLeft + MarginIncrement) <= MarginMax Then .MarginLeft = (.MarginLeft + MarginIncrement)
            If (.MarginTop + MarginIncrement) <= MarginMax Then .MarginTop = (.MarginTop + MarginIncrement)
            If (.MarginRight + MarginIncrement) <= MarginMax Then .MarginRight = (.MarginRight + MarginIncrement)
        End With
        End If
        Next
    End Sub
    
    
    Sub MarginDecrease()
    Dim oshp As Shape
    For Each oshp In ActiveWindow.Selection.ShapeRange
    If oshp.HasTextFrame Then
    With oshp.TextFrame
        If (.MarginBottom - MarginIncrement) >= 0 Then .MarginBottom = (.MarginBottom - MarginIncrement)
        If (.MarginLeft - MarginIncrement) >= 0 Then .MarginLeft = (.MarginLeft - MarginIncrement)
        If (.MarginTop - MarginIncrement) >= 0 Then .MarginTop = (.MarginTop - MarginIncrement)
        If (.MarginRight - MarginIncrement) >= 0 Then .MarginRight = (.MarginRight - MarginIncrement)
    End With
    End If
    Next
    End Sub
    
    
    Sub MarginNone()
    Dim oshp As Shape
    For Each oshp In ActiveWindow.Selection.ShapeRange
    If oshp.HasTextFrame Then
    With oshp.TextFrame
        .MarginBottom = 0
        .MarginLeft = 0
        .MarginTop = 0
        .MarginRight = 0
    End With
    End If
    Next
    End Sub


    I came across to unforeseen cases. if the shape is a table, nothing happens. Am I correct in supposing I have to loop through all cells?

    The other case, which applies to both regular shapes and tables is in dealing with the title line.

    Shape Table

    _________
    | Shape 1 |
    ------------
    | Shape 2 |
    | |
    -------------

    Shape one should not modify, Shape 2 Should. If more than one shape group is selected then each should be processed in the same way.

    Please help!
    Thanks in advance

Posting Permissions

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