【问题标题】:VBA PowerPoint - Restricting macro only for specific slideVBA PowerPoint - 仅针对特定幻灯片限制宏
【发布时间】:2020-01-14 00:21:48
【问题描述】:

我正在尝试对我的 PowerPoint 宏执行错误处理,除非您在幻灯片 5 上,否则该宏会限制您运行宏。我正在尝试使用命令:“Application.ActiveWindow.View 5 Then”,但它似乎没有认识到我在幻灯片 5 上,它的正确命令是什么?

Private Sub CommandButton1_Click()

    Dim Sld As Slide
    Dim Shp As Shape

    'ERROR HANDLING
        If ActivePresentation.Slides.Count < 5 Then
            MsgBox "You do not have any slides in your PowerPoint project."
            Exit Sub
        End If

    Set Sld = Application.ActiveWindow.View.Slide

        If activeSlide <> 5 Then
            MsgBox "You are not on the correct slide."
            Exit Sub
        End If

    Set Sld = Application.ActiveWindow.View.Slide
End Sub

【问题讨论】:

  • 你已经捕获了Sld。你不能说If Sld.Number &lt;&gt; 5 Then之类的话吗?另外,不需要第二个Set Sld

标签: vba powerpoint


【解决方案1】:

activeSlide 不是 PowerPoint 对象,您还没有将其定义为其他任何东西,请将其替换为 Sld 并添加 SlideIndex 以获得号码:

Private Sub CommandButton1_Click()

    Dim Sld As Slide
    Dim Shp As Shape

    'ERROR HANDLING
        If ActivePresentation.Slides.Count < 5 Then
            MsgBox "You do not have any slides in your PowerPoint project."
            Exit Sub
        End If

    Set Sld = Application.ActiveWindow.View.Slide

        If Sld.SlideIndex <> 5 Then
            MsgBox "You are not on the correct slide."
            Exit Sub
        End If

End Sub

【讨论】:

  • 非常感谢,这正是我想要的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-01
  • 1970-01-01
  • 2015-06-16
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多