Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM

oBOM.PartsOnlyViewEnabled = True

Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Strukturalny")

xlApp = CreateObject("Excel.Application")

'comment out or change to false
'in order to not show Excel
xlApp.Visible = True
xlWorkbook = xlApp.Workbooks.Open("C:\Temp\Szablon.xlsx")

xlWorksheet = xlWorkbook.Worksheets.Item("BOM")

Dim row As Integer
row = 3

'xlWorksheet.Range("B4").Value = "ITEM"
'xlWorksheet.Range("C4").Value = "QTY"
'xlWorksheet.Range("D4").Value = "DESC"
'xlWorksheet.Range("E4").Value = "Part Number"

'Dim bRow As bomRow
bRows = oBOMView.BOMRows
For Each bRow In bRows

Dim rDoc As Document
rDoc = bRow.ComponentDefinitions.Item(1).Document

Dim docPropertySet As PropertySet
docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")

xlWorksheet.Range("A" & row).Value = bRow.ItemNumber
xlWorksheet.Range("B" & row).Value = docPropertySet.Item("Part Number").Value
xlWorksheet.Range("C" & row).Value = bRow.ItemQuantity
xlWorksheet.Range("D" & row).Value = docPropertySet.Item("Stock number").Value
xlWorksheet.Range("E" & row).Value = docPropertySet.Item("Vendor").Value
xlWorksheet.Range("F" & row).Value = docPropertySet.Item("Description").Value
xlWorksheet.Range("G" & row).Value = docPropertySet.Item("Cost").Value


row = row + 1
Next


Dim r As Range 
' How many Colums defined by G how many rows defined by i
r= xlWorksheet.Range("A1:G" & i)

'IE
'r= xlWorksheet.Range("A1:G100") r.Sort(r.Columns(1), XlSortOrder.xlAscending, , , , , , XlYesNoGuess.xlYes, , , XlSortOrientation.xlSortColumns, XlSortMethod.xlPinYin, ) oNow = DateString & "_" & TimeString oNow = oNow.Replace("/","_") oNow = oNow.Replace(":","_") xlWorkBook.SaveAs(Filename:="C:\Temp\BOM-" & oNow & ".xlsx") xlWorkbook.Close (True) xlApp.Quit

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !