Use VBA to change the internal margin and/or number format of a PowerPoint table cell
13,333
With objTable.Rows(the_row).Cells(the_col).Shape.TextFrame
'Internal margin:
.MarginLeft = 'value goes here
.MarginRight = 'value goes here
.MarginTop = 'value goes here
.MarginBottom= 'value goes here
'number Format:
.TextRange.text = Format(1000, "#,##0.00") 'replace 1000 with your value
end with
Author by
rryanp
Updated on June 04, 2022Comments
-
rryanp almost 2 years
I have a VBA loop that cycles through the selected cells of a PowerPoint table to update the formatting. The following lines work great:
With objTable.Rows(the_row).Cells(the_col).Shape.TextFrame.TextRange.Font .Size = 12 .Color = RGB(0, 0, 102) End With With objTable.Rows(the_row).Cells(the_col).Shape.TextFrame .VerticalAnchor = msoAnchorMiddle End With
I'm having trouble finding the syntax to modify the number format (to change the number of decimals, add a comma, etc.) and to change the internal margin of the cell (which I can do manually with a right click -> Format Shape -> Text Box -> Internal Margin). Usually I use the record macro option to get to that detailed syntax, but I'm not seeing that option in PowerPoint.
-
rryanp almost 11 yearsI had tried this and it didn't work, but it just hit me that the value probably has to be in pixels and not inches...is that right? And for the number format, the number is already there, so would this work: .TextRange.Text = Format(.TextRange.Text, "#,##0.00")? Thanks!
-
rryanp almost 11 yearsI just tested both of those things, and they both work (use pixels and send the text range value as a parameter of the Format function). Thanks a lot for your help!
-
Steve Rindsberg almost 11 yearsValues are POINTS, not pixels
-
Gobe over 8 yearsUse VBA function InchesToPoints