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

VBA code to change path of all excel file link objects, shapes and graphs in PPT
Raghavendra BBusiness Operations AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kathy JacobsSocial media geekCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Raghavendra BBusiness Operations AnalystAuthor Commented:
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 AnalystAuthor Commented:
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Raghavendra BBusiness Operations AnalystAuthor Commented:
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 AnalystAuthor Commented:
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 geekCommented:
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 AnalystAuthor Commented:
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 geekCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.