Consulting

Results 1 to 2 of 2

Thread: VBA for align text in shape or selected table cells

  1. #1
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location

    VBA for align text in shape or selected table cells

    Hi John, I've tried about 2 hours and several different version of code for something so simple (not for me though!).

    I need code please that aligns table text in PowerPoint for selected cells. That also works in for a text box. I know there's tools and button already, but making a ribbon I can't insert the msoNAME for these tools. I need a tool to align text to the top. (I can then guestimate for middle and bottom).

    Code I ended up close to it is:

    [VBA]
    Sub AlignTop()


    Dim tbl As Table
    Dim iCol As Integer
    Dim iRow As Integer
    Dim I As Integer
    On Error GoTo err


    Dim X As Integer
    Dim Y As Integer
    Dim otbl As Table
    Dim B As Long
    On Error GoTo err:
    Set otbl = ActiveWindow.Selection.ShapeRange(1).Table
    otbl.Parent.Height = 0
    For X = 1 To otbl.Columns.Count
    For Y = 1 To otbl.Rows.Count
    With otbl.Cell(Y, X)
    .Shape.TextFrame2.VerticalAnchor = msoAnchorTop
    End With


    End Sub


    [/VBA]

    Your wisdom is much appreciated, thank you. And take care in these strange times.
    Thank you.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Maybe

    Sub AlignTop()
    
    Dim iCol As Integer
    Dim iRow As Integer
    Dim otbl As Table
    On Error GoTo Err
    
    
    Set otbl = ActiveWindow.Selection.ShapeRange(1).Table
    otbl.Parent.Height = 0
    For iRow = 1 To otbl.Rows.Count
    For iCol = 1 To otbl.Columns.Count
    
    
    With otbl.Cell(iRow, iCol)
    .Shape.TextFrame2.VerticalAnchor = msoAnchorTop
    End With
    Next iCol
    Next iRow
    Exit Sub
    Err:
    MsgBox "There was an error: " & Err.Description, vbCritical
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

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
  •