Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click

Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

FixLinks prevents broken links when you distribute PowerPoint presentations

Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing

PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

Search and Replace for Hyperlinks, OLE links, movie links and sound links

Problem

You have a presentation that includes an extensive collection of hyperlinks to various external files.

Then a server name or mapped drive letter changes and all of your links break.

Or you've moved your Excel files from one directory to another and now the links don't work.

You know that all you need to do is change, say, the "P:\" in each link to the new drive name "Q:\" and a simple Search and Replace would do the job. Unfortunately, PowerPoint's Search and Replace feature doesn't work with hyperlink text, so you're stuck doing all of the replacements one at a time by hand.

Or ... you could try this:

Solution

This macro will ask you what text you want to search for and what you want to replace it with.
That it will look at each hyperlink in your presentation and do the search/replace on both the hyperlink Address and Subaddress.

If you're not familiar with hyperlink Address and SubAddress, have a look here:
Hyperlink .SubAddress - How to interpret it

And to get a look at the hyperlinks in the presentation before you start to search and replace, see Show Me: The hyperlinks in my presentation or use the Links Report feature of the free PPTools FixLinks demo.

Here's the code:

Option Explicit

Sub HyperLinkSearchReplace()

    Dim oSl As Slide
    Dim oHl As Hyperlink
    Dim sSearchFor As String
    Dim sReplaceWith As String
    Dim oSh As Shape

    sSearchFor = InputBox("What text should I search for?", "Search for ...")
    If sSearchFor = "" Then
        Exit Sub
    End If

    sReplaceWith = InputBox("What text should I replace" & vbCrLf _
        & sSearchFor & vbCrLf _
        & "with?", "Replace with ...")
    If sReplaceWith = "" Then
        Exit Sub
    End If

    On Error Resume Next

    For Each oSl In ActivePresentation.Slides

        For Each oHl In oSl.Hyperlinks
            oHl.Address = Replace(oHl.Address, sSearchFor, sReplaceWith)
            oHl.SubAddress = Replace(oHl.SubAddress, sSearchFor, sReplaceWith)
        Next    ' hyperlink

        ' and thanks to several astute user suggestions, let's fix OLE links 
        ' and movie/sound linkes too
        For Each oSh In oSl.Shapes
           If oSh.Type = msoLinkedOLEObject _
            Or oSh.Type = msoMedia Then
              oSh.LinkFormat.SourceFullName = _
                   Replace(oSh.LinkFormat.SourceFullName, _
                   sSearchFor, sReplaceWith)
           End If
       Next

    Next    ' slide

End Sub

Limitations

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2009 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Search and Replace for Hyperlinks, OLE links, movie links and sound links
http://www.pptfaq.com/FAQ00773.htm
Last update 11 December, 2009
Created: