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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.
http://www.pptfaq.com/FAQ00759_Search_-_Replace_to_change_OLE_link_paths.htm

https://exceloffthegrid.com/edit-links-in-powerpoint-using-vba/

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:
Hi,
Thanks for the information, am getting error "13 type mismatch", for the below line -
"osld.Shapes"
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)

' EDIT THIS TO REFLECT THE PATHS YOU WANT TO CHANGE
sOldPath = "D:\Demographics\3.13.18\PPTs\"
sNewPath = "D:\Demographicss\3.13 .18\PPTss\testings\"
'D:\Demographic\3.13.18\PPT

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.Update
            oSh.LinkFormat.AutoUpdate = ppUpdateOptionManual

        End If
    Next oSh
Next osld
pptPresentation.Save

MsgBox ("Done!")

NormalExit:
    Exit Sub

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

End Sub
Raghavendra BBusiness Operations AnalystAuthor Commented:
Hi,
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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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...
http://www.pptfaq.com/FAQ00407_Add_the_current_path_and_file_to_every_slide.htm

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
VBA

From novice to tech pro — start learning today.