vba 如何使用vba获得power point幻灯片尺寸?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8999796/
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
How to get power point slide dimension using vba?
提问by Pratik Gujarathi
I am working on one project. In which i want to find out " Is my textbox going out of slide or not?" . If yes then show error msg.
我正在做一个项目。我想在其中找出“我的文本框是否从幻灯片中消失?” . 如果是,则显示错误消息。
so my logic is if i found the dimension of the slide then i will use it in IF...Else condition like :
所以我的逻辑是,如果我找到了幻灯片的尺寸,那么我将在 IF...Else 条件下使用它,例如:
If textbox_position < slide_dimension then
#Error
end if
If you have any other idea then please tell me.
如果您有任何其他想法,请告诉我。
Thanks
谢谢
回答by Steve Rindsberg
The presentation's .PageSetup.SlideWidth and .SlideHeight properties will give you the dimensions of the slide in points.
演示文稿的 .PageSetup.SlideWidth 和 .SlideHeight 属性将以磅为单位提供幻灯片的尺寸。
Your function would need to do something like (off top of head and out of the air ..):
你的函数需要做一些类似的事情(头顶和空中..):
Function IsOffSlide (oSh as Shape) as Boolean
Dim sngHeight as single
Dim sngWidth as Single
Dim bTemp as Boolean
bTemp = False ' by default
With ActivePresentation.PageSetup
sngHeight = .SlideHeight
sngWidth = .SlideWidth
End With
' this could be done more elegantly and in fewer lines
' of code, but in the interest of making it clearer
' I'm doing it as a series of tests.
' If any of them are true, the function will return true
With oSh
If .Left < 0 Then
bTemp = True
End If
If .Top < 0 Then
bTEmp = True
End If
If .Left + .Width > sngWidth Then
bTemp = True
End If
If .Top + .Height > sngHeight Then
bTemp = True
End If
End With
IsOffSlide = bTemp
End Function
回答by Bruno Leite
Why you not use a placeholders of PowerPoint to make this? for example:
你为什么不使用 PowerPoint 的占位符来制作这个?例如:
Sub SetText(IndexOfSlide As Integer, txt As String)
'http://officevb.com
ActivePresentation.Slides(IndexOfSlide).Shapes.Placeholders(1).TextFrame.TextRange.Text = txt
End Sub
You can call this sub and pass parameters
您可以调用此子程序并传递参数
IndexOfSlide with a number of slide and txt with a text to create.
IndexOfSlide 用多个slide 和txt 用一个文本来创建。