VBA in powerpoint to break links

pbarry

Board Regular
Joined
Aug 15, 2013
Messages
122
Didn't know where this belonged, but since it's a VBA question I figured it's safe to post in this section. I need to update links in powerpoint vba then immediately break the link that was updated. I have a template created where the macro kicks off and pulls data to a file that has links to the powerpoint. Once the data needed is extracted it is in the format as it needs to be in, then the charts get updated and saved as the correct filename/extension. At this point it is how I planned. However, the excel file that the charts are linked to will be getting altered and written over each subsequent time the macro is ran. So, anybody that refreshes these files will get the wrong data for that 'named file'. I thought I found code to break the links, but apparently the object type in this occurrence is 'msoPlaceholder' and I can't get the code to function as such. I can get it done manually, which essentially the entire reason why there is VBA so we can get this done in one fell swoop.

Found this code online, as well as about 4 others and I am losing my mind.

Code:
Dim oSld As Slide
    Dim oSh As Shape


    For Each oSld In ActivePresentation.Slides
        For Each oSh In oSld.Shapes
            If oSh.Type = msoPlaceholder Then
                oSh.LinkFormat.BreakLink
            End If
        Next   ' Shape
    Next   ' Slide
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This code, running in PowerPoint, should remove all hyperlinks in a presentation:

Code:
Option Explicit

Sub RemoveHyperlinks()

    Dim oSld As Slide
    Dim hyp As Hyperlink

    For Each oSld In ActivePresentation.Slides
        For Each hyp In oSld.Hyperlinks
            hyp.Delete
        Next   ' Hyperlink
    Next   ' Slide
    
End Sub
 
Last edited:
Upvote 0
Will this break links from the charts, or just hyperlinks? Or, is this placeholder object acting as a hyperlink?
 
Upvote 0
I walked through the code and there seems to not have been any hyperlinks. There are objects with links to an excel file, and I have to manually break links for now, but I don't understand how a .breaklinks code doesn't work on it?
 
Upvote 0
Found code here:
How to convert charts --> Pictures in Powerpoint using VBA - Microsoft Community

Code:
Option Explicit

Sub EnumChartsInPresentation()
    Dim sld As Slide
    Dim shp As Shape
    Dim ctr As Long
    For Each sld In ActivePresentation.Slides
        For ctr = sld.Shapes.Count To 1 Step -1
            If GetShapeType(sld.Shapes(ctr)) = msoChart Then
                Call ConvertChartToImage(sld, sld.Shapes(ctr))
            End If
        Next
    Next
End Sub
 
Function GetShapeType(shp As Shape) As MsoShapeType
    If shp.Type = msoPlaceholder Then
        If shp.PlaceholderFormat.ContainedType = msoChart Then
            GetShapeType = msoChart
            Exit Function
        End If
    End If
    GetShapeType = shp.Type
End Function
 
Sub ConvertChartToImage(sld As Slide, shp As Shape)
    Dim shpChartImage As Object
    shp.Copy
    DoEvents
    Set shpChartImage = sld.Shapes.PasteSpecial(ppPastePNG)
    With shpChartImage
        .Left = shp.Left
        .Top = shp.Top
        
        Do While shp.ZOrderPosition < shpChartImage.ZOrderPosition
            Call shpChartImage.ZOrder(msoSendBackward)
        Loop
        
        shp.Visible = False
        'shp.Delete
        'Set shp = Nothing
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,218,076
Messages
6,140,313
Members
450,278
Latest member
cpatten

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