Hi there,
Possibly not the correct place to pose this question as strictly its PowerPoint VBA, but I'm hoping the issue is simple enough that someone here might be able to help.
I have an Excel spreadsheet that produces and updates graphs. These are copied into a PowerPoint that is sent to a client. When they receive the Excel + Powerpoint the links are broken because they reference directories on my PC. I am trying to automatically edit these links with VBA before I send the PowerPoint so that they reference a non-existent directory on my end, but accurately reflect the directory on the client end.
Currently the script I have is causing a Run-time error -2147188160, which I understand from this link https://support.microsoft.com/en-gb/...ntation-call-i requires a piece of additional VBA to ensure the application is visible (the PowerPoint would be running and visible when the script to change the links is run, but anyway). I've tried to add the recommended code, but still get the Run-time error -2147188160 error.
I have the following references running:- Visual Basic for Applications
- Microsoft PowerPoint 16.0 Object Library
- OLE Automation
- Microsoft Office 16.0 Object Library
- Microsoft Excel 16.0 Object Library
- AutoEvents
- FM20.dll
Any and all help greatly appreciated.
Sub UpdateLinks()
Dim oldFilePath As String
Dim newFilePath As String
Dim pptPresentation As Presentation
Dim pptSlide As Slide
Dim pptShape As Shape
If PowerPoint.Application.Version >= 9 Then
'window must be visible
PowerPoint.Application.Visible = msoTrue
End If
'The old file path as a string (the text to be replaced)
oldFilePath = "" 'filepathhere
'The new file path as a string (the text to replace with)
newFilePath = "" 'file path here
'Set the variable to the PowerPoint Presentation
Set pptPresentation = ActivePresentation
'Loop through each slide in the presentation
For Each pptSlide In pptPresentation.Slides
'Loop through each shape in each slide
For Each pptShape In pptSlide.Shapes
'Find out if the shape is a linked object or a linked picture
If pptShape.Type = msoLinkedPicture Or pptShape.Type _
= msoLinkedOLEObject Or pptShape.Type = msoChart Then
'Use Replace to change the oldFilePath to the newFilePath
pptShape.LinkFormat.SourceFullName = Replace(VBA.LCase$ _
(pptShape.LinkFormat.SourceFullName), VBA.LCase$(oldFilePath), newFilePath)
End If
Next
Next
'Update the links
pptPresentation.UpdateLinks
End Sub
Bookmarks