I have a code which loop through all the slides in the active presentation and checks for the name of the shape and then breaks the linking. Now, I want to rename that shape. The problem is that the shape automatically gets converted to a picture and the PowerPoint automatically assigns a name on which I do not have control. Object Required error is shown. Is there a solution to this?
VBA Code:
Sub BreakLinksInPPT()
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim Newshp As Shape
Dim UniqueName As String
'Open PowerPoint Application
Set pptApp = GetObject(Class:="Powerpoint.Application")
'Open the presentation you want to break links in
Set pptPres = pptApp.ActivePresentation
'Loop through each slide in the presentation
For Each sld In pptPres.Slides
'Loop through each shape in the slide
For Each shp In sld.Shapes
UniqueName = "HNM" & Format(Now, "yyyymmddhhmmss")
'Check if the shape is linked to an external file
If Left(shp.Name, 3) = "HNM" Then
If shp.Type = 10 Then
'Break the link
shp.LinkFormat.BreakLink
shp.Name = UniqueName
End If
End If
Next shp
Next sld
End Sub