gpt4 book ai didi

vba - 引用 powerpoint 演示文稿和幻灯片时出现错误 451

转载 作者:行者123 更新时间:2023-12-02 22:49:10 24 4
gpt4 key购买 nike

我继承了一些使用三个全局变量的代码

Global PPTApp As PowerPoint.Application
Global PPTPres As PowerPoint.Presentation
Global PPtSlides As PowerPoint.Slide

稍后在代码中按以下方式使用它们

Sub PasteTablesPPT(TargetText As String, PPTRange As Range)

Dim TargetSlide As PowerPoint.Slide

PPTApp.Activate

For Each PPtSlides In PPTPres.Slides 'Error on colleagues PC
With PPtSlides.Shapes.Title.TextFrame
If .HasText Then
If UCase(.TextRange.Text) = UCase(TargetText) Then
TargetNum = CInt(PPtSlides.SlideIndex)
Exit For
End If
End If
End With
Next

在我的电脑上,这按其应有的方式工作,即它激活打开的 powerpoint 应用程序,然后循环播放该演示文稿中的每张幻灯片。

但是,在我的同事电脑上,我标记的线路上出现了错误。具体错误为Error 451 我认为这与 PPtSlides 未被识别为 PPtPres.Slides 的一部分有关。同样在 Debug模式下,当我将鼠标悬停在 PPtSlides 上时,它显示“Nothing”

我们在 VBA 工具中进行了相同的引用检查,谁能解释一下为什么这适用于我的电脑而不是我的同事?

编辑:定义 PPTPres 的部分(在另一个子中,这只是该子的摘录)

On Error GoTo ErrHandler
Set PPTApp = GetObject(class:="PowerPoint.Application")
PPTApp.Visible = msoTrue
Set PPTPres = PPTApp.Presentations("Testing File")
Exit Sub

最佳答案

在子 PasteTablesPPT 中,尝试将 PPtSlides 声明为 PowerPoint.Slide

dim PPtSlides as PowerPoint.Slide

关于vba - 引用 powerpoint 演示文稿和幻灯片时出现错误 451,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33690421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com