如何使用VBA获取PowerPoint幻灯片的尺寸?

13

我正在开发一个项目。我想要找出“我的文本框是否超出了幻灯片的范围,如果是,则显示错误消息。”

因此,我的逻辑是,如果我找到幻灯片的尺寸,那么我将在IF...Else条件语句中使用它:

If textbox_position < slide_dimension  then
#Error
end if

如果你有其他想法,请告诉我。

谢谢。

2个回答

20
演示文稿的 .PageSetup.SlideWidth 和 .SlideHeight 属性会给出幻灯片的点数尺寸。
您的函数需要执行类似以下内容的操作(仅凭记忆和经验):
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

1

为什么不使用PowerPoint的占位符来制作呢?例如:

Sub SetText(IndexOfSlide As Integer, txt As String)
'http://officevb.com
       ActivePresentation.Slides(IndexOfSlide).Shapes.Placeholders(1).TextFrame.TextRange.Text = txt
End Sub

你可以调用这个子程序并传递参数。
IndexOfSlide 是幻灯片编号,txt 是要创建的文本。

非常感谢你,布鲁诺。让我试试看。 - Pratik Gujarathi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接