Consulting

Results 1 to 3 of 3

Thread: Change paddings using VBA

  1. #1

    Change paddings using VBA

    Hello,
    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
    ActivePresentation.Slides(1).Select
    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 !
    Platypuce

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

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

Posting Permissions

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