BOMRow.ComponentDefinitions(1).ReferenceComponents.DerivedPartComponents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need to export out all the part(s) that go into a derived part into an excel spreadsheet. I already am exporting what I need from the BOM and putting it into an excel spreadsheet but it doesn't catch anything below a derived part. If it is derived from a part, I would just need the part, but if it is a derived assembly, I need the entire structure of the assembly. Someone suggested using this:
BOMRow.ComponentDefinitions(1).ReferenceComponents.DerivedPartComponents
I don't know enough yet to understand how I can use this to accomplish what I need, can someone help?
Thanks,
This is what I have so far:
Sub BOM_Export()
Dim oApp As Application
Set oApp = ThisApplication
If oApp.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Dim oAssyDoc As AssemblyDocument
Set oAssyDoc = oApp.ActiveDocument
Dim oAssyCompDef As AssemblyComponentDefinition
Set oAssyCompDef = oAssyDoc.ComponentDefinition
'Dim excel_app As Excel.Application
' Create the Excel application.
Set excel_app = CreateObject("Excel.Application")
' Uncomment this line to make Excel visible.
excel_app.Visible = True
'Create new workbook
Call excel_app.Workbooks.Add
Dim oBomR As BOMRow
Dim oBOMPartNo As String
Dim oBomComments As String
Dim odoc As Document
Set odoc = ThisApplication.ActiveDocument
Dim oPropSet As PropertySet
Set oPropSet = ThisApplication.ActiveDocument.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")
Dim oProp As Property
Set oProp = oPropSet.Item("Comments")
Dim sProp As String
sProp = Right(odoc.FullFileName, Len(odoc.FullFileName) - InStrRev(odoc.FullFileName, "\"))
' This strips off the last 4 digits of the filename.
sProp = Left(sProp, Len(sProp) - 4)
With excel_app
.Range("A:A").ColumnWidth = 20
.Range("B:B").ColumnWidth = 20
.Range("A1").Select
.ActiveCell.Value = "Part Number"
.Range("B1").Select
.ActiveCell.Value = "Copied From"
.Range("A2").Select
.ActiveCell.Value = sProp
.Range("B2").Select
.ActiveCell.Value = oProp.Value
Dim ad As AssemblyDocument
Set ad = ThisApplication.ActiveDocument
Dim acd As AssemblyComponentDefinition
Set acd = ad.ComponentDefinition
Dim bom As bom
Set bom = acd.bom
' Enable both Structured View and PartOnlyView
bom.StructuredViewEnabled = True
bom.StructuredViewFirstLevelOnly = False
bom.PartsOnlyViewEnabled = True
'Iterate through parts only BOM View
Dim i As Integer
For i = 1 To oAssyCompDef.bom.BOMViews(3).BOMRows.Count
'Set oBomR to current BOM Row
Set oBomR = oAssyCompDef.bom.BOMViews(3).BOMRows(i)
'Get Current Row part number from part
oBOMPartNo = oBomR.ComponentDefinitions(1).Document.PropertySets(3).ItemByPropId(5).Value
'Get Current comments from BOM
oBomComments = oBomR.ComponentDefinitions(1).Document.PropertySets.Item("Summary Information").Item("Comments").Value
'Write values to spreadsheet
i = i + 1
.Range("A" & i + 1).Select
.ActiveCell.Value = oBOMPartNo
.Range("B" & i + 1).Select
.ActiveCell.Value = oBomComments
i = i - 1
Next i
excel_app.ActiveWorkbook.Saveas FileName:="C:\Users\ShaStu\Documents\" & sProp & ".xlsx"
excel_app.Workbooks.Close
excel_app.Quit
End With
End If
End Sub