使用 VBA 更改 PowerPoint 表格单元格的内部边距和/或数字格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16695720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use VBA to change the internal margin and/or number format of a PowerPoint table cell
提问by rryanp
I have a VBA loop that cycles through the selected cells of a PowerPoint table to update the formatting. The following lines work great:
我有一个 VBA 循环,它循环浏览 PowerPoint 表格的选定单元格以更新格式。以下几行效果很好:
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.
我无法找到修改数字格式(更改小数位数、添加逗号等)和更改单元格内部边距的语法(我可以通过右键单击 -> 格式手动执行此操作)形状 -> 文本框 -> 内部边距)。通常我使用记录宏选项来获取详细的语法,但我在 PowerPoint 中没有看到该选项。
回答by ZebraOnWheels
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