PDA

View Full Version : how to Formatt Table in vba code



selva_235
08-08-2016, 06:36 AM
Hi,

I need to format table single and single slides not all the slides in powerpoint vba code. (Font Size and Alignment). Is its possible to powerpoint. I have attached the file for your reference.

Thanks
Selva

John Wilson
08-09-2016, 08:25 AM
To format a selected table in vba you need to loop through each cell. This may be slightly slow in a big table.

This is an example to get you started then you will need to try and adapt


Sub tabler()
Dim iRow As Integer
Dim iCol As Integer
Dim otbl As Table
On Error Resume Next
If ActiveWindow.Selection.ShapeRange(1).HasTable Then
Set otbl = ActiveWindow.Selection.ShapeRange(1).Table
For iRow = 1 To otbl.Rows.Count
For iCol = 1 To otbl.Columns.Count
With otbl.Cell(iRow, iCol).Shape.TextFrame2
.VerticalAnchor = msoAnchorMiddle
.TextRange.Font.Size = 12
End With
If iRow = otbl.Rows.Count Then ' bottom row only
With otbl.Cell(iRow, iCol).Borders(ppBorderBottom)
.Visible = True
.ForeColor.RGB = RGB(120, 120, 120)
.Weight = 1
End With
End If
Next iCol
Next iRow
End If
End Sub