I am working on a macro to rename all of the parts in an assembly. I have gotten all of the "Part Numbers" to update to the new numbers but am having a hard time saving "Save As" all of the files so that the file has the same name as the part number. I started by trying to save at the same time as I changed the part number but it seems very difficult to jump between products and their respective document to be able to save. I therefore went the route shown below of just saving all of the documents by recursively scrolling though the tree and saving any parts. It still isn't working though. Any suggestions?
Sub SaveParts(oInDocuments As Documents, oInPart As PartDocument, ByVal bLevel As Integer, DocPath As String)
bLevel = bLevel + 1
Dim oInst As Documents
Set oInst = oInDocuments
Dim PartDoc As PartDocument
Set PartDoc = oInPart
'No components --> CATPart
If oInst.Count = 0 Then
oInPart.SaveAs (DocPath & "\" & PartDoc.Part.Name & ".CATPart")
Exit Sub
End If
'Multiple components --> CATProduct
Dim i As Integer
For i = 1 To oInst.Count
Dim partType As String
partType = oInst.Item(i).Name
partType = Right(partType, 2)
If partType = "rt" Then
Dim Part2 As PartDocument
Set Part2 = oInst.Item(i)
Else
Dim nInst As Documents
Set nInst = oInst.Item(i)
End If
Call SaveParts(nInst, Part2, bLevel, DocPath)
Next
End Sub
Sub SaveParts(oInDocuments As Documents, oInPart As PartDocument, ByVal bLevel As Integer, DocPath As String)
bLevel = bLevel + 1
Dim oInst As Documents
Set oInst = oInDocuments
Dim PartDoc As PartDocument
Set PartDoc = oInPart
'No components --> CATPart
If oInst.Count = 0 Then
oInPart.SaveAs (DocPath & "\" & PartDoc.Part.Name & ".CATPart")
Exit Sub
End If
'Multiple components --> CATProduct
Dim i As Integer
For i = 1 To oInst.Count
Dim partType As String
partType = oInst.Item(i).Name
partType = Right(partType, 2)
If partType = "rt" Then
Dim Part2 As PartDocument
Set Part2 = oInst.Item(i)
Else
Dim nInst As Documents
Set nInst = oInst.Item(i)
End If
Call SaveParts(nInst, Part2, bLevel, DocPath)
Next
End Sub