Consulting

Results 1 to 3 of 3

Thread: Seemingly random error with paragraph spacing

  1. #1
    VBAX Regular
    Joined
    Oct 2016
    Posts
    45
    Location

    Seemingly random error with paragraph spacing

    So, I'm using a macro to align text boxes across multiple slides (one slide at a time, select text box to align with macro, click the assigned macro button, rinse and repeat).

    Most of the time it works absolutely fine. But then on random slides (I can't work out the pattern), the paragraph spacing (.SpaceAfter) goes wrong. Instead of, in this particular example, a space of 3 pts between paragraphs, it will set it to 28.8 pts between paragraphs.

    For the life of me, I cannot work out why this is happening. It would be less confusing if it happened all the time, but on most slides it works fine!

    Any help is appreciated. Current version of the code I'm using is below.

    Sub TextBoxAlign()If ActiveWindow.Selection.Type <> ppSelectionShapes Then Exit Sub
    With ActiveWindow.Selection.ShapeRange(1)
        .LockAspectRatio = False
        .Height = cm2Points(0.6)
        .Width = cm2Points(25.24)
        .Left = cm2Points(0)
        .Top = cm2Points(13.69)
        
        With .TextFrame
            .WordWrap = True
            .VerticalAnchor = msoAnchorBottom
            .AutoSize = ppAutoSizeNone
            
            With .TextRange
                
                With .Font
                    .Size = 8
                    .Name = "Arial(Body)"
                    .Bold = False
                    .Color.RGB = RGB(92, 92, 92)
                End With
                
                With .ParagraphFormat
                    .SpaceBefore = 0
                    .SpaceAfter = 3
                    .Alignment = ppAlignLeft
                End With
            
            End With
        End With
    End With
    End Sub
    
    Function cm2Points(inVal As Single)
    cm2Points = inVal * 28.346
    End Function
    (I take no credit for any of this code, as it has been cobbled together from the hard work of others; I think it was originally John Wilson who developed the original code).

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    .SpaceAfter / .SpaceBefore sets the value to xx LINES or xx POINTS

    This is governed by setting .LineRuleAfter / .LineRuleBefore to True or False

    Since you haven't set this it just depends on the current setting which may look fairly random.

    If you are using a modern version I would also use new TextRange2 features and kill the error you will get if the selected shape does not have a textframe

    This should get you started (again)

    Sub TextBoxAlign()
    On Error Resume Next
    Dim oshp As Shape
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    If Not oshp Is Nothing And oshp.HasTextFrame Then
     With oshp
            .LockAspectRatio = False
            .Height = cm2Points(0.6)
            .Width = cm2Points(25.24)
            .Left = cm2Points(0)
            .Top = cm2Points(13.69)
            
            With .TextFrame2
                .WordWrap = True
                .VerticalAnchor = msoAnchorBottom
                .AutoSize = ppAutoSizeShapeToFitText
                With .TextRange
                    With .Font
                        .Size = 8
                        .Name = "Arial(Body)"
                        .Bold = False
                        .Fill.ForeColor.RGB = RGB(92, 92, 92)
                    End With
                     
                    With .ParagraphFormat
                    .LineRuleAfter = msoFalse
                        .SpaceBefore = 0
                        .SpaceAfter = 3
                        .Alignment = ppAlignLeft
                    End With
                     
                End With
            End With
        End With
        End If ' something is wrong
    End Sub
     
    Function cm2Points(inVal As Single)
        cm2Points = inVal * 28.346
    End Function
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Oct 2016
    Posts
    45
    Location
    John, thank you so much for your help! Really appreciate you taking the time.

Tags for this Thread

Posting Permissions

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