Compile Error - Object Required

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Compile Error - Object Required

Post by D Willett »

Hi Guys.
I'm creating a spreadsheet to change charts in a Powerpoint Presentation from the following youtube video:

https://www.youtube.com/watch?v=Z8WUSIg ... eOfficeLab

This is the module:

Code: Select all

Sub Refresh(ParamArray var() As Variant)
Dim pApp As Object
Dim pPreso As Object
Dim pSlide As Object
Dim sPreso As String

'Define your PowerPoint Dashboard File Path
sPreso = "C:\MIC\Powerpointdash\Dash.pptx"


'Open and reference PowerPoint Dashboard File


On Error Resume Next
    Set pApp = GetObject(, "PowerPoint.Application")

If Err.Number <> 0 Then
    Set pApp = CreateObject("PowerPoint.Application")
    pApp.Visible = True
End If

On Error Resume Next
    Set sPreso = (pApp.Presentations(sPreso))
    
   If Err.Number <> 0 Then
   Set sPreso = (pApp.Presentations.Open(Filename:=sPreso)) ' ERROR OCCURS ON THIS LINE
    
'Update every chart in ParamArray var

Dim varSize As Integer
Dim i As Integer

varSize = UBound(var) - LBound(var) + 1
   
For i = 0 To (varSize - 1)
    pPreso.Slides(1).Shapes(var(i)).LinkFormat
Next i


End Sub
I am getting a compile error, Object required on the following line:

Set sPreso = (pApp.Presentations(sPreso))

Any idfeas why I am getting this?

Cheers
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Compile Error - Object Required

Post by HansV »

You have two lines that begin with Set sPreso = ...
Both should begin with Set pPreso = ...
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Compile Error - Object Required

Post by D Willett »

Yes his coding does differ in the Comments than the video. I found a couple more typo's and now all works fine.

Thanks again Hans.
( Ihope you are well )
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Compile Error - Object Required

Post by HansV »

I'm fine, thank you. I hope you are too.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: Compile Error - Object Required

Post by D Willett »

All good here Hans :cheers:
Cheers ...

Dave.