3
votes

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.

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".

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?

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

On Error GoTo ErrHandler
    Set PPTApp = GetObject(class:="PowerPoint.Application")
    PPTApp.Visible = msoTrue
    Set PPTPres = PPTApp.Presentations("Testing File")
Exit Sub
1
Are you using the same PPT file?Nathan_Sav
If you check the value of PPtSlides while the line is in yellow, it is normal that it says nothing as the line hasn't been executed yet. Though, can you add the part were PPTPres is defined? It is most probably coming from there. And just a remark, to respect conventions, it'd be easier for understanding to have PPtSlide instead of PPtSlides as it for a single Slide and not the Collections.R3uK
Same version of PowerPoint?John Coleman
Yep, same version of PP and same file being used.user3737057
The error seems to be a collection based one, so was thinking it could be the .slides collection of the PPT, but not sure now :)Nathan_Sav

1 Answers

0
votes

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

dim PPtSlides as PowerPoint.Slide