运行时错误' -2147188160(80048240)' vba powerpoint

时间:2015-05-15 18:24:12

标签: vba powerpoint powerpoint-vba powerpoint-2013

我正在使用代码通过命令按钮或宏将表示属性显示到文本框或形状。当我运行它时,我得到一个运行时错误,说" SlideShowWindows(未知成员):整数超出范围。 1不在1到0的有效范围内

我该怎么办!? 提前谢谢!

Sub ReportStuff()
    Dim oSl As Slide
    Dim oSh As Shape

    Set oSl = SlideShowWindows(1).View.Slide

    ' Test to see if the shape's already there:
    Set oSh = IsItThere(oSl, "My Text Box")

    ' If it's not there, add it:
    If oSh Is Nothing Then
       Set oSh = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 50)
       oSh.Name = "My Text Box"
    End If

    With oSh.TextFrame.TextRange
        .Text = "Index: " & oSl.SlideIndex & " ID: " & oSl.SlideID & " File: " & ActivePresentation.FullName
    End With

End Sub

Function IsItThere(oSl As Slide, sName As String) As Shape
   Dim oSh As Shape
   For Each oSh In oSl.Shapes
      If oSh.Name = sName Then
         Set IsItThere = oSh
         Exit Function
      End If
   Next
End Function

1 个答案:

答案 0 :(得分:0)

SlideShowWindow只能在幻灯片放映期间访问,而不能在普通/编辑模式下访问。在Set oSl = SlideShowWindows(1).View.Slide之上添加以下代码行应该会有所帮助:

ActivePresentation.SlideShowSettings.run