Macro Fails Because of Component
Macro Fails Because of Component
(OP)
I have the following section of a large Macro that fails when it encounters a Component, instead of a product.
What is the best way to handle components since they do not have a save feature?
Error Message:
Run-Time error -2147467259 (80004005)
The Method ReferenceProduct Failed
It fails at the this line:
If Right(sel.Item(X).LeafProduct.ReferenceProduct.Parent.Name, 7) = "Product" Then
Section of Code
What is the best way to handle components since they do not have a save feature?
Error Message:
Run-Time error -2147467259 (80004005)
The Method ReferenceProduct Failed
It fails at the this line:
If Right(sel.Item(X).LeafProduct.ReferenceProduct.Parent.Name, 7) = "Product" Then
Section of Code
CODE --> VBA
Dim sel As Selection Set sel = CATIA.ActiveDocument.Selection sel.Search "CATAsmSearch.Product,all" For X = 1 To sel.Count If X = 1 Then Input1TopProduct = sel.Item(X).LeafProduct.ReferenceProduct.Parent.Product.PartNumber End If 'Checking To See If Current Item X is a Product If Right(sel.Item(X).LeafProduct.ReferenceProduct.Parent.Name, 7) = "Product" Then ' If MsgBox(sel.Item(X).LeafProduct.ReferenceProduct.Parent.Name, vbOKCancel, "Product") = vbCancel Then ' MsgBox ("Canceled") ' Exit Sub ' End If Set oDoc1 = sel.Item(X).LeafProduct.ReferenceProduct.Parent Set oProduct1 = oDoc1.Product 'Get The Current Product Number InputProd = oProduct1.PartNumber 'Check To See If Suffix Has Already Been Applied If Right(InputProd, Input1CharacterLength) = InputSuffix1 Then 'Do Nothing Else 'Creating The Current Product Number with Suffix InputsuffixedProd = oProduct1.PartNumber & InputSuffix1 'Removing Periods From Product Number to Prevent Any Errors in Saving InputsuffixedProd = Replace(InputsuffixedProd, ".", "_") InputsuffixedProd = Replace(InputsuffixedProd, ".", "_") InputsuffixedProd = Replace(InputsuffixedProd, "/", "_") InputsuffixedProd = Replace(InputsuffixedProd, "#", "_") InputsuffixedProd = Replace(InputsuffixedProd, "____", "_") InputsuffixedProd = Replace(InputsuffixedProd, "___", "_") InputsuffixedProd = Replace(InputsuffixedProd, "__", "_") 'Changing the Current ProductNumber To Include Suffix oProduct1.PartNumber = InputsuffixedProd 'Saving Current Product As New Name Into Input1-1 Folder oDoc1.SaveAs Folder1 & "\" & oProduct1.PartNumber & ".CATProduct" End If End If 'Checking To See If Current Item X is a Part If Right(sel.Item(X).LeafProduct.ReferenceProduct.Parent.Name, 4) = "Part" Then ' If MsgBox(sel.Item(V).LeafProduct.ReferenceProduct.Parent.Name, vbOKCancel, "Part") = vbCancel Then ' MsgBox ("Canceled") ' Exit Sub ' End If Set oDoc2 = sel.Item(X).LeafProduct.ReferenceProduct.Parent Set oPart1 = oDoc2.Product 'Get The Current Part Number InputPart = oPart1.PartNumber 'Check To See If Suffix Has Already Been Applied If Right(InputPart, Input1CharacterLength) = InputSuffix1 Then 'Do Nothing Else 'Creating The Current Part Number with Suffix Input1suffixedPart = oPart1.PartNumber & InputSuffix1 'Removing Periods From Part Number to Prevent Any Errors in Saving Input1suffixedPart = Replace(Input1suffixedPart, ".", "_") Input1suffixedPart = Replace(Input1suffixedPart, "/", "_") Input1suffixedPart = Replace(Input1suffixedPart, "#", "_") Input1suffixedPart = Replace(Input1suffixedPart, "____", "_") Input1suffixedPart = Replace(Input1suffixedPart, "___", "_") Input1suffixedPart = Replace(Input1suffixedPart, "__", "_") 'Changing the Current ProductNumber To Include Suffix oPart1.PartNumber = Input1suffixedPart 'Saving Current Part As New Name Into Input1-1 Folder oDoc2.SaveAs Folder1 & "\" & oPart1.PartNumber & ".CATPart" End If End If Next
RE: Macro Fails Because of Component
CODE --> catvba