A few years ago, my colleague Wayne composed a blog on how to remove missing OLE links. Recently, a customer wanted to remove any OLE links when checking in to Vault. Ideally, he needs an iLogic code. So I refactored a little with the code Wayne demoed in VBA and iLogic:
Sub Main()
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
If TypeOf oDoc Is AssemblyDocument Then
Call compositeDoc(oDoc)
ElseIf TypeOf oDoc Is PartDocument Then
Call singleDoc(oDoc)
ElseIf TypeOf oDoc Is DrawingDocument Then
Call singleDoc(oDoc)
Else
Call MsgBox("wrong file type!")
End If
Call oDoc.Update2(True)
End Sub
Sub singleDoc(doc)
Dim oEachOLEDesc As ReferencedOLEFileDescriptor
For Each oEachOLEDesc In doc.ReferencedOLEFileDescriptors
oEachOLEDesc.Delete
doc.Dirty = True
Next
End Sub
Sub compositeDoc(parentAssDoc)
'remove links of top document
Call singleDoc(parentAssDoc)
'remove links of sub document
For Each oEachDesc In parentAssDoc.ReferencedDocumentDescriptors
Dim doc As Document
doc = oEachDesc.ReferencedDocument
Dim oEachOLEDesc As ReferencedOLEFileDescriptor
For Each oEachOLEDesc In doc.ReferencedOLEFileDescriptors
oEachOLEDesc.Delete
doc.Dirty = True
Next
If TypeOf doc Is AssemblyDocument Then
Call compositeDoc(doc)
End If
Next
End Sub
The below code is written in VBA.
Sub breakLinks()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If TypeOf oDoc Is AssemblyDocument Then
Call compositeDoc(oDoc)
ElseIf TypeOf oDoc Is PartDocument Then
Call singleDoc(oDoc)
ElseIf TypeOf oDoc Is DrawingDocument Then
Call singleDoc(oDoc)
Else
Call MsgBox("wrong file type!")
End If
Call oDoc.Update2(True)
End Sub
Sub singleDoc(doc)
Dim oEachOLEDesc As ReferencedOLEFileDescriptor
For Each oEachOLEDesc In doc.ReferencedOLEFileDescriptors
oEachOLEDesc.Delete
doc.Dirty = True
Next
End Sub
Sub compositeDoc(parentAssDoc)
'remove links of top document
Call singleDoc(parentAssDoc)
'remove links of sub document
For Each oEachDesc In parentAssDoc.ReferencedDocumentDescriptors
Dim doc As Document
Set doc = oEachDesc.ReferencedDocument
Dim oEachOLEDesc As ReferencedOLEFileDescriptor
For Each oEachOLEDesc In doc.ReferencedOLEFileDescriptors
oEachOLEDesc.Delete
doc.Dirty = True
Next
If TypeOf doc Is AssemblyDocument Then
Call compositeDoc(doc)
End If
Next
End Sub