VBA code to change path of all excel file link objects, shapes and graphs in PPT

Raghavendra B
Raghavendra B used Ask the Experts™
VBA code to change path of all excel file link objects, shapes and graphs in PPT
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Social media geek
One of these two code examples seem to be what you are looking for is in this PPT FAQ entry. If not, they should at least give you a starting point.


If that doesn't do what you need, let us know.
Raghavendra BBusiness Operations Analyst


Thanks for the information, am getting error "13 type mismatch", for the below line -
this is the code -
Sub ChangeOLELinks()

Dim osld As Slide
Dim oSh As Shape
Dim sOldPath As String
Dim sNewPath As String

Dim pptApp As PowerPoint.Application
    Dim sourceFileName As String
    Dim pptPresentation As Object
    sourceFileName = "D:\Demographics\3.13.18\PPTs\testings\tests1\InTC Demographicss_Jan-2018.pptx"
    Set pptApp = New PowerPoint.Application

'Make the PowerPoint application visible
pptApp.Visible = True

'Set the variable to the PowerPoint Presentation
Set pptPresentation = pptApp.Presentations.Open(sourceFileName)

sOldPath = "D:\Demographics\3.13.18\PPTs\"
sNewPath = "D:\Demographicss\3.13 .18\PPTss\testings\"

On Error GoTo ErrorHandler

For Each osld In pptPresentation.Slides
    For Each oSh In osld.Shapes
        If oSh.Type = msoLinkedOLEObject Then

            Dim stringPath   As String
            stringPath = Replace(oSh.LinkFormat.SourceFullName, sOldPath, sNewPath, 1, , vbTextCompare)

            oSh.LinkFormat.SourceFullName = stringPath
           ' set update mode to auto and update then set it back to manual
            oSh.LinkFormat.AutoUpdate = ppUpdateOptionAutomatic
            oSh.LinkFormat.AutoUpdate = ppUpdateOptionManual

        End If
    Next oSh
Next osld

MsgBox ("Done!")

    Exit Sub

    MsgBox ("Error " & Err.Number & vbCrLf & Err.Description)
    Resume NormalExit

End Sub
Raghavendra BBusiness Operations Analyst


I got the solution, need to change Dim oSh As Shape as "Dim oSh As PowerPoint.Shape",
the code is working only for worksheet type, but its not changing the chart type, need advice
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Raghavendra BBusiness Operations Analyst


I changed all the graphs to worksheet type and macro has worked perfectly,
 Is there a way to find current folder path which are linked to ppt using VBA???
Raghavendra BBusiness Operations Analyst


Thanks for the link, it saved lot of time, I need to know the current linked path to ppt and get that path in a cell or textbox
Kathy JacobsSocial media geek

I am guessing you are having problems with getting the path. If you want to do this from PPT, you are probably going to want to use either the path property for the presentation (ActivePresentation.path) OR the FullName property (ActivePresentation.FullName). I am not sure what the difference is, but I would trust .FullName more than .path

Once again, the PPT FAQ comes through...

Bookmark that site. You will find it an absolutely amazing place for answers on most things PowerPoint.
Raghavendra BBusiness Operations Analyst


Thanks for help, i did try the code which in that link, but din't get any output,

I will give the user command button to browse and select the new link to update ppt
My requirement is -
2) VBA code to get the current link path automatically so that i can use the macro to replace with new path.
thinking how to get the current linked path string in a textbox???
Kathy JacobsSocial media geek

Not sure how to get the string to a textbox, I haven't done that... I do more stuff with the actual slides.... both in the code I write and in the code I test.

I am wondering if it is time to add the textbox part as a new question so that someone who has experience with that task can help you out. When you do that, it might be a good idea to give a screenshot of what the code you are using is doing that isn't what you want it to do.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial