Results 1 to 3 of 3

Thread: Change paddings using VBA

  1. #1

    Change paddings using VBA

    Iím new to VBA, and Iím working on Powerpoint 2016. Iím looking to change the properties of a "Shape" object with VBA.
    I have a single Slide with a single Shape object,which is a table (or list) of 4 columns over 10 rows, with text in each of the cells (I donít know if in PowerPoint, the term "cell" is adapted).
    I manage to change properties of the Shape object such as Left, Top, Height, Width, but now I have to change the internal margins (or padding) in my table cells.
    I guess I have to act on the "TextFrame" object and the MarginLeft property for example.
    The following code is used:
    Dim myShape As Shape
    Set myShape = ActivePresentation.Slides(1).Shapes(1)
          myShape.TextFrame.MarginLeft = 5
    and does not work, and an error message "The specified value is out of range" appears.
    Can you help me understand my mistake?

    Note: I have tested the property " HasTextFrame " and the message box is displaying "0", which I guess means that the TextFrame is NULL.
    But why, as the Shape contains text?

    Thanks !

  2. #2
    VBAX Master
    Feb 2007
    Tables do not have a textframe. They contain cells which DO.

    You need to loop through each cell like this:

    Sub int_margins()
    Dim otbl As Table
    Dim iRow As Integer
    Dim iCol As Integer
    On Error Resume Next
    Set otbl = ActiveWindow.Selection.ShapeRange(1).Table
    If Not otbl Is Nothing Then
    For iRow = 1 To otbl.Rows.Count
    For iCol = 1 To otbl.Columns.Count
    With otbl.Cell(iRow, iCol).Shape.TextFrame
    .MarginTop = 0
    .MarginBottom = 0
    .MarginLeft = 0
    .MarginRight = 0
    End With
    Next iCol
    Next iRow
    End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials

  3. #3
    Hi John Wilson,
    Thank you for your reply.
    This is what I was searching for, and will help me a lot.

Posting Permissions

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