如何使用vba获取幻灯片尺寸?

发布于 2024-12-28 14:55:53 字数 229 浏览 2 评论 0原文

我正在做一个项目。我想知道“我的文本框是否超出幻灯片范围?” 。如果是,则显示错误消息。

所以我的逻辑是,如果我找到幻灯片的尺寸,那么我将在 IF...Else 条件下使用它,例如:

If textbox_position < slide_dimension  then
#Error
end if

如果您有任何其他想法,请告诉我。

谢谢

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 textbox_position < slide_dimension  then
#Error
end if

If you have any other idea then please tell me.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小墨 2025-01-04 14:55:53

演示文稿的 .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

The presentation's .PageSetup.SlideWidth and .SlideHeight properties will give you the dimensions of the slide in points.

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
绝情姑娘 2025-01-04 14:55:53

为什么不使用 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(包含要创建的文本)。

Why you not use a placeholders of PowerPoint to make this? for example:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文