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

时间:2022-09-03 22:30:55

I have inherited some code which uses three global variables

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

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

Later on in the code it uses them in the following way

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

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

On my PC this works as it should i.e. it activates the open powerpoint application and then loops through each of the slides within that presentation.

在我的电脑上,这应该工作,即它激活开放的powerpoint应用程序,然后循环遍历该演示文稿中的每个幻灯片。

However on my colleagues PC, the runs into an error on the line I have flagged. The specific error is Error 451 and I think it's to do with PPtSlides not being recognized as part if PPtPres.Slides. Also in debug mode when I hover over PPtSlides it says ="Nothing".

但是在我的同事PC上,在我标记的行上遇到错误。特定错误是错误451,我认为这与PPtSlides没有被识别为PPtPres.Slides的一部分有关。同样在调试模式下,当我将鼠标悬停在PPtSlides上时,它表示=“Nothing”。

We have the same references check in VBA tools, could anyone shed some light on why this would work on my PC and not my colleagues?

我们在VBA工具中使用相同的参考文件,是否有人可以解释为什么这可以在我的PC而不是我的同事上工作?

EDIT: The part where PPTPres is defined (in another sub and this is just an extract of that sub)

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

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

1 个解决方案

#1


0  

In the sub PasteTablesPPT, try to declare PPtSlides as PowerPoint.Slide

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

dim PPtSlides as PowerPoint.Slide

#1


0  

In the sub PasteTablesPPT, try to declare PPtSlides as PowerPoint.Slide

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

dim PPtSlides as PowerPoint.Slide