使用 VBA 在 PowerPoint 中设置对象的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20753305/
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
Setting an object's position in PowerPoint using VBA
提问by user1533277
I am using the following lines of VBA to set the size/position of an Excel selection I just pasted into PowerPoint:
我正在使用以下 VBA 行来设置我刚刚粘贴到 PowerPoint 中的 Excel 选择的大小/位置:
Set Shp = _
PPApp.ActivePresentation.Slides( _
PPApp.ActiveWindow.Selection.SlideRange.slideindex).Shapes(3)
Shp.ScaleHeight 0.75, msoCTrue
Shp.ScaleWidth 0.75, msoCTrue
Shp.Left = 0.58
Shp.Top = 1.6
However, after the macro runs, my shape has horizontal position of 0.01" from the top left corner and a vertical position of "0.02" from the top left corner. Based on my code, the position should be 0.58 and 1.6. Any ideas of why the position is not being set properly?
但是,在宏运行后,我的形状距左上角的水平位置为 0.01",距左上角的垂直位置为 "0.02"。根据我的代码,该位置应为 0.58 和 1.6。任何想法为什么位置设置不正确?
采纳答案by Steve Rindsberg
To add to what Tim's said, PowerPoint uses points as its system of measurement, at least for purposes of automation, so do this instead:
为了补充蒂姆所说的,PowerPoint 使用点作为其测量系统,至少出于自动化的目的,所以请改为这样做:
Shp.Left = 0.58 * 72
Shp.Top = 1.6 * 72