picklefactory
Well-known Member
- Joined
- Jan 28, 2005
- Messages
- 508
- Office Version
- 365
- Platform
- 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
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