VBA 不循环播放任何 PowerPoint 幻灯片
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 中是否有一些设置或参数需要激活?
感谢任何帮助。
试试这个:
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
VBA 必须知道您指的是哪个应用程序,以便它循环遍历该应用程序中的对象。
1.打开 VBA 编辑器
2。在顶部功能区中,单击 Tools
> References
,然后选中 Microsoft PowerPoint X.0 Object Library
复选框
现在您可以确定要引用的 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
我只是尝试使用 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 中是否有一些设置或参数需要激活?
感谢任何帮助。
试试这个:
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
VBA 必须知道您指的是哪个应用程序,以便它循环遍历该应用程序中的对象。
1.打开 VBA 编辑器
2。在顶部功能区中,单击 Tools
> References
,然后选中 Microsoft PowerPoint X.0 Object Library
现在您可以确定要引用的 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