[英]VBA not looping through any PowerPoint slides
我只是想在Excel中使用以下VBA代碼循環瀏覽PowerPoint幻燈片。
Sub test()
Dim slide As Object
For Each slide In ActivePresentation.Slides
Debug.Print "test"
Next slide
End Sub
但是,我收到消息“運行時錯誤'424”。 所需對象'。 有人知道為什么ActivePresentation.Slides可能不起作用嗎? 我也嘗試將Dim slide as Slide
。
我需要激活PowerPoint中的某些設置或參數嗎?
任何幫助表示贊賞。
VBA必須知道您所指的是哪個應用程序,才能使其遍歷該應用程序內的對象。
1.打開VBA編輯器
2.在頂部功能區中,單擊“ Tools
>“ References
,然后選中“ Microsoft PowerPoint X.0對象庫”框。
現在,您可以識別要引用的PowerPoint應用程序和演示文稿
Sub ppslides()
Dim pp As Object
Dim slide As Object
Dim PowerPoint As PowerPoint.Application
Set PowerPoint GetObject(, "PowerPoint.Application")
'Loops through each open PP presentation and puts the presentation name in a messagebox
For Each pp In PowerPoint.Presentations
MsgBox pp.Name
Next pp
'These variables can be populated and used to refer to a specific Presentation in the upcoming loop
ppname = "Example"
ppindex = 1
'Loops through all slides in the presentation and puts their names in a messagebox
'REF should be replaced with a name, index, or one of the above variables
For each slide In PowerPoint.Presentations(REF).Slides
MsgBox slide.Name
Next slide
End Sub
嘗試這個:
Sub test()
Dim objPPTApp As Object
Dim slide As Object
Set objPPTApp = GetObject(, "PowerPoint.Application")
For Each slide In objPPTApp.ActivePresentation.Slides
Debug.Print "test"
Next slide
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.