Share via

PP2010 VBA Format Tables

Anonymous
2014-11-10T10:14:16+00:00

I'm looking for faster ways to format a table in VBA than cell by cell, which is like watching paint dry.

In the UI, I can select groups of columns and then click "Distribute columns evenly".

How do you select multiple columns in VBA?

Once selected I can then use Commandbars.executemso "TableColumnsDistribute"

In the same way, how do I set the cell padding for all cells in a table, in one statement.

I can see an mso TableCellMarginsGallery but not how to set, say, narrow margins for all cells in a table.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-11-10T12:18:13+00:00

Support for Tables in the PPT object model is not great!

I don't think it is possible to select more than one column in code.

You can simulate distribute columns like this and it should run fairly quickly

Sub distribute_Cols(otbl As Table, fromCol As Long, toCol As Long)

Dim L As Long

Dim totW As Single

Dim colW As Single

Dim numCols As Long

For L = fromCol To toCol

totW = totW + otbl.Columns(L).Width

Next

numCols = (toCol - fromCol) + 1

colW = totW / numCols

For L = fromCol To toCol

otbl.Columns(L).Width = colW

Next

End Sub

To set narrow margins you will have to loop through the cells and set each textframe margin to about 3.7 points. If you avoid selecting anything this shouldn't be too slow.

Sub setmargins(otbl As Table, LM As Single, RM As Single, TM As Single, BM As Single)

Dim iRow As Integer

Dim iCol As Integer

For iRow = 1 To otbl.Rows.Count

For iCol = 1 To otbl.Columns.Count

otbl.Cell(iRow, iCol).Shape.TextFrame.MarginBottom = BM

otbl.Cell(iRow, iCol).Shape.TextFrame.MarginTop = TM

otbl.Cell(iRow, iCol).Shape.TextFrame.MarginLeft = LM

otbl.Cell(iRow, iCol).Shape.TextFrame.MarginRight = RM

Next iCol

Next iRow

End Sub

Was this answer helpful?

0 comments No comments

12 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-11-10T16:25:24+00:00

    Hi,

    You cannot use executemso to execute item in a gallery. So you will have to rely on code to achieve the task.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-11-10T15:10:24+00:00

    No maybe in this case ;-)

    I used to avoid the whole problem by creating it nicely in Excel and then pasting pictures of the chart or range to PP but now they want actual tables in PP to allow selecting the text.

    A time sink, yes, but a good client who in turn has important clients, so they get service "like it used to be"!

    Nice VBA resources on your site, too.

    BTW I thought I was on to something with .Select Replace:=False but find that only applies to Shapes, not Columns. Ah well.

    Cheers

    P

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2014-11-10T13:58:03+00:00

    If you're a pro programmer and the client mentions PowerPoint, Tables or Charts in the same breathe....

    Time to say "Maybe BUT ...."

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-11-10T12:38:26+00:00

    Thanks John,

    That's what I'm doing at the moment, I was hoping for faster methods.

    It's a pity PP does not expose all the methods we'd like.

    I copy from Excel having set widths there as much as I can and then paste to PP using CommandBars.ExecuteMso "PasteExcelTableSourceFormatting"

    I find the ExecuteMso method needs Doevents before and after to give PP time to catch up before I can access the newly pasted table object.

    Was this answer helpful?

    0 comments No comments