Updating links in PPT, VBA error

picklefactory

Well-known Member
Joined
Jan 28, 2005
Messages
506
Office Version
  1. 365
Platform
  1. Windows
Hi folks
I know this is a PPT question, but I think the VBA is similar and you guys are the bees knees.
I've searched the forum and online and found some code (It's above my meagre level) that seems to work for most people, but I have a glitch I can't fathom, hoping someone here can spot the issue.
I have a PPT that has a number of linked Excel sheets that I wish to update periodically automatically (I think I can modify an OnTime udf for that, I'll dabble with that later). Most of the link update code seems to run until it gets to Filepath = Left(SourceFile, Position - 1) where it hangs with "Run time error 'Invalid procedure call or argument'" where the code is looking to remove the cell references and just leave the file path.

What I suspect MIGHT be the issue is that some of the linked Excel object file paths do not contain a "!", but some of them do, so I'm wondering if it's hanging when it can't find a "!"
Would that make sense? Can I test for that or put some sort of If statement in to accommodate that? Or is it something completely different?
Cheers gang


VBA Code:
Sub UpdateLinks()

    'Declare powerpoint variables
    Dim PPTSlide As Slide
    Dim PPTShape As Shape
    Dim SourceFile, Filepath As String
    Dim Position As Integer
    
    'Declare Excel variables
    Dim xlApp As Excel.Application
    Dim xlWrkbook As Excel.Workbook
    
    'Create a new instance of Excel
    Set xlApp = New Excel.Application
        xlApp.Visible = False
        xlApp.DisplayAlerts = False
        
    'Loop through the slides in the presentation.
    For Each PPTSlide In ActivePresentation.Slides
    
        'Loop through each shape in the slide
        For Each PPTShape In PPTSlide.Shapes
        
            'If the shape is a linked object, continue
            If PPTShape.Type = msoLinkedOLEObject Then
            
                'Get the linked source name
                SourceFile = PPTShape.LinkFormat.SourceFullName
                
                
               'Parse the source file name
               Position = InStr(1, SourceFile, "!", vbTextCompare)
               Filepath = Left(SourceFile, Position - 1)
               
               'Open the associated Excel workbook
               Set xlWrkbook = xlApp.Workbooks.Open(Filepath, False, True)
               
                'Update the link
                PPTShape.LinkFormat.Update
                
                
            'Close the workbook and erase it from memory
            xlWrkbook.Close
            Set xlWrkbook = Nothing
                    
                
            End If
        
        Next
        
    Next
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Oooh..... wonders will never cease.... I think I fixed it, and for once I was actually correct on the issue. The alteration below now works.
I'll tick as resolved

VBA Code:
               'Parse the source file name
               If InStr(SourceFile, "!") > 0 Then
               Position = InStr(1, SourceFile, "!", vbTextCompare)
               Filepath = Left(SourceFile, Position - 1)
               Else: Filepath = SourceFile
               End If
 
Upvote 0
Solution

Forum statistics

Threads
1,215,073
Messages
6,122,974
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top