VBA 幻灯片'-2147188160 (80048240)'运行时错误



我正在使用代码通过命令按钮或宏将表示属性呈现给文本框或形状。当我运行它时,我得到一个运行时错误,说"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

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

ActivePresentation.SlideShowSettings.run

相关内容

最新更新