尝试将标题居中时,PowerPoint的VBA错误(424:必需的对象)

时间:2018-07-11 23:38:53

标签: vba powerpoint

With myPresentation.Slides(index).Shapes(1).TextFrame.TextRange.Text
        .Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2
        .Top = (ActivePresentation.PageSetup.SlideHeight - .Height) / 2
End With

所以基本上我有一张带有1个标题对象的幻灯片,并且我正在尝试将其格式化为居中位置,

.Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2

但是此行抛出对象必需错误。感谢您的帮助

1 个答案:

答案 0 :(得分:0)

Shape对象具有LeftTopWidthHeight属性。在这种情况下,TextFrameTextRangeText无关。

Option Explicit

Sub CenterTitle()
    Dim myPresentation As Presentation: Set myPresentation = ActivePresentation

    With myPresentation.Slides(1).Shapes(1)
        .Left = (myPresentation.PageSetup.SlideWidth - .Width) / 2
        .Top = (myPresentation.PageSetup.SlideHeight - .Height) / 2
    End With
End Sub