New drive mapping for powerpoint linked objects - VBA solution

Viewed 474

All linked objects (linked to excel) in a powerpoint are no longer recognized as IT have migrated the server to a new path and turned off the old one.

I have tried using the macro below from (https://exceloffthegrid.com/edit-links-in-powerpoint-using-vba/) but because the old server is no longer running, when the macro attempts to open the old file path, it errors

Is there an alternative solution?


Sub EditPowerPointLinks()

Dim oldFilePath As String
Dim newFilePath As String
Dim pptPresentation As Presentation
Dim pptSlide As Slide
Dim pptShape As Shape

'The old file path as a string (the text to be replaced)
oldFilePath = "String of\File Path\To Be Replaced\Excel File.xlsx"

'The new file path as a string (the text to replace with)
newFilePath = "String of\New File Path\Excel File 2.xlsx"

'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 Then

            'Use Replace to change the oldFilePath to the newFilePath
            pptShape.LinkFormat.SourceFullName = Replace(LCase _
            (pptShape.LinkFormat.SourceFullName), LCase(oldFilePath), newFilePath)

        End If
    Next
Next

'Update the links
pptPresentation.UpdateLinks


End Sub
1 Answers

Your code is okay, I also tested it.

The setting of new links are handled different by the application:

  • If you set a new SourceFullName of a linked picture (Shape.Type = msoLinkedPicture),
    the application accepts anything as link, and the code raises no error.
  • If you try to set a new SourceFullName of a linked OLE object (Shape.Type = msoLinkedOLEObject), the application immediately tests, if the new file is really there.
    You'll get an error, if the linked OLE object does not exist.

Result: You have to ensure, that the new path points to an existing file (and you need appropriate access rights for it).

Related