Find and replace using PPT VBA

raghavcacs

Board Regular
Joined
Mar 13, 2009
Messages
84
Hi,

The question regarding Find and replace in PPT VBA. I am trying to find the file path of the linked objects in a PPT and replace part of it with the latest files. Can you please help me how to do it?

Find = March month file name
Replace = April month file name

This ppt has more than 200 links from the same file. Hence going by the usual "Edit links" is laborious and time consuming.

Any help on this would be highly appreciable.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The first macro replaces part of the filename for all linked objects in the active slide. The second one replaces part of the filename for all linked objects in all slides in the active presentation. For these two examples, it simply replaces "March" with "April", so you may need to amend it accordingly. Note that the code must be placed in a regular module within your PowerPoint presentation file.

For the active slide...

Code:
Sub UpdateLinkedObjectsInActiveSlide()


    Dim oSlide As Slide
    Dim oShape As Shape
    
    Set oSlide = Application.ActiveWindow.View.Slide
    
    For Each oShape In oSlide.Shapes
        If oShape.Type = msoLinkedOLEObject Then
            oShape.LinkFormat.SourceFullName = Replace(oShape.LinkFormat.SourceFullName, "March", "April", 1, 1, vbTextCompare)
        End If
    Next oShape
    
End Sub

For all slides in the active presentation...


Code:
Sub UpdateLinkedObjectsInActivePresentation()


    Dim oSlide As Slide
    Dim oShape As Shape
    
    For Each oSlide In ActivePresentation.Slides
        For Each oShape In oSlide.Shapes
            If oShape.Type = msoLinkedOLEObject Then
                oShape.LinkFormat.SourceFullName = Replace(oShape.LinkFormat.SourceFullName, "March", "April", 1, 1, vbTextCompare)
            End If
        Next oShape
    Next oSlide


End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,547
Messages
6,120,139
Members
448,948
Latest member
spamiki

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