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

我已经inheritance了一些使用三个全局variables的代码

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 

在我的电脑上,这个function应该是可以的,也就是说,它会激活开放的PPT应用程序,然后循环播放演示文稿中的每个幻灯片。

然而,在我的同事电脑上,我遇到了一个错误 。 具体的错误是错误451 ,我认为这是做PPtSlides不被识别为一部分,如果PPtPres.Slides。 同样在debugging模式下,当我hover在PPtSlides它说=“没有”

我们在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