2015-05-15 767 views
0

我正在使用代碼通過命令按鈕或宏將呈現屬性呈現給文本框或形狀。當我運行它,我得到那個說「SlideShowWindows(未知成員)運行時錯誤:整數超出範圍1不是1的有效範圍爲0運行時錯誤'-2147188160(80048240)'vba powerpoint

我該怎麼辦!? 感謝英寸推進

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 

回答

0

SlideShowWindow是幻燈片時才能訪問,而不是在正常/編輯模式下添加以下代碼行上述Set oSl = SlideShowWindows(1).View.Slide應該有所幫助:!

ActivePresentation.SlideShowSettings.run 
+0

你已經有一個線程在這個小號ame主題進行;請不要啓動其他線程。 –

+0

你在說什麼? – Sam

+0

也許這不是你的線程,但你從這裏複製了代碼,不是嗎? http://stackoverflow.com/questions/30261814/add-powerpoint-slide-to-textbox-with-commandbutton-vba保持對它的迴應只會有道理。 –