Macro to Break Links

Mdl0377

New Member
Joined
Apr 30, 2023
Messages
3
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Web
Hi all. I'm stumped. I have multiple PowerPoints and need an Excel macro to break links. I Update Links when prompted as I open the PPTs, save them as new files with current date, then need to break all links so they don't change later.

I'm trying to write a macro to do the following:
Prompt user to select PowerPoint file
Break Links
Save & Close file
Prompt for next file...break...save, etc.

I want it to do the same thing as if I were to manually break the links, like this:
Open the PowerPoint file
File
Info
Edit Links to Files
Break Link (until all are removed)
Close window
Save & Close PowerPoint.

Am I having trouble because there needs to be something that updates the files as they are opened to be broken? I update the links when I open them to save as a new file, but I can't help but think it's a problem with needing to update again prior to breaking links.

here's my macro...

Sub BreakLinksInPowerPointFiles()

Dim ppApp As Object

Dim ppPresentation As Object

Dim wb As Workbook

Dim ws As Worksheet

Dim fileDialog As fileDialog

Dim filePath As String

Dim moreToBreak As Boolean



Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)

Set ppApp = CreateObject("PowerPoint.Application")



With fileDialog

.Title = "Select PowerPoint File"

.Filters.Clear

.Filters.Add "PowerPoint Files", "*.pptx"



Do

moreToBreak = False

If .Show = -1 Then

filePath = .SelectedItems(1)

Set ppPresentation = ppApp.Presentations.Open(filePath)

For Each ws In ThisWorkbook.Sheets

ws.Cells.Clear ' Clear any previous data in the Excel sheet

Next ws



' Break links in the PowerPoint presentation

For Each oleObj In ppPresentation.Slides(1).Shapes

If oleObj.Type = 3 Then ' Check if it's a linked OLE object

oleObj.LinkFormat.BreakLink

End If

Next oleObj



ppPresentation.Save

ppPresentation.Close

moreToBreak = True

Else

Exit Do

End If

Loop While moreToBreak



Set ppPresentation = Nothing

ppApp.Quit

Set ppApp = Nothing

End With



MsgBox "You've broken all the links!", vbInformation

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
To update your links, add the following line after you've opened the presentation...

VBA Code:
ppPresentation .UpdateLinks

Hope this helps!
 
Upvote 0
Solution
To update your links, add the following line after you've opened the presentation...

VBA Code:
ppPresentation .UpdateLinks

Hope this helps!
I appreciate that Domenic. Sadly, the security settings on my work computer require that I manually click update, or manually approve the part of a macro that would force the update.
 
Upvote 0
Have you tried placing your presentation in a trusted location (File >> Options >> Trust Center >> Trust Center Settings >> Trusted Locations) ?
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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