By Wayne Brill
Here is a VBA example that uses the Delete method of the ReferencedOLEFileDescriptor in a part file to remove OLE links. SilentOperation of the Application is set to True to avoid dialogs.
Also the Dirty property of the document is set to True. I found that without doing this the save did not save to disk with the removed Links.
This ivb has code that removes the links in a part as well as removing the links in parts in an assembly. It is an update to the AssemblyCount VBA example in the API help.
Public Sub oleLinksDelete()
ThisApplication.SilentOperation = True
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.ActiveDocument
Dim bSaveDoc As Boolean
bSaveDoc = False
Dim oRefOleFileDesc As ReferencedOLEFileDescriptor
If oPartDoc.ReferencedOLEFileDescriptors.Count > 0 Then
For Each oRefOleFileDesc In _
oPartDoc.ReferencedOLEFileDescriptors
'Debug.Print oRefOleFileDesc.ReferenceStatus
If oRefOleFileDesc.ReferenceStatus = _
kMissingReference Then
' Debug.Print oRefOleFileDesc.DisplayName
oRefOleFileDesc.Delete
oPartDoc.Dirty = True
bSaveDoc = True
End If
Next oRefOleFileDesc
If bSaveDoc = True Then
oPartDoc.Save
bSaveDoc = False
End If
End If
' Be sure to set this back to False
ThisApplication.SilentOperation = False
End Sub