Sub CATMain()
'now loop though all the child products of the root product.
Dim subProduct As Product
For i = 1 To rootProduct.Products.Count
Set subProduct = rootProduct.Products.Item(i)
'call the (recursive) function to copy it's parts to the new part
Call CopySubProduct(subProduct, newPart)
Next
rootProduct.Update
MsgBox bodyCount & " Part Bodies copied"
End Sub
' if it is a part, make sure the part body is published and then
' copy-paste-special-as-result the part body into the new part
ElseIf InStr(aSubProduct.ReferenceProduct.Parent.Name, ".CATPart") =
Len(aSubProduct.ReferenceProduct.Parent.Name) - 7 Then
Debug.Print aSubProduct.Name; " is a Part"
Call CopyPasteAsResultPartBody(aSubProduct, targetPart)
'get the part body to copy. It must be published. Because you never go to the
Part object (via product.referenceproduct.parent.part)
' the publication allows you to keep the instance-ism of each part intact.
sel.Clear
Dim j, k As Integer
For j = 1 To sourcePartProduct.Publications.Count
sel.Add sourcePartProduct.Publications.Item(j)
On Error Resume Next
sel.Copy
sel.Clear
sel.Add targetPart
On Error Resume Next
sel.PasteSpecial ("CATPrtResult")
sel.Clear
Next
bodyCount = bodyCount + 1
End Sub