Message 1 of 7
is there a way to make this run faster ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this code it is look like it work .... but on big iam it is very slow.
is there a better and faster way to do the same
Class BOMEXport
Shared row As Integer = 2
Public Sub Main()
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewDelimiter = "."
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
Call ExportToExcel(oBOMView.BOMRows)
GoExcel.Save
GoExcel.Close
End Sub
Public Sub debug(txt As String)
Trace.WriteLine("NTI : " & txt)
End Sub
Public Function ExportToExcel(bRows As BOMRowsEnumerator)
ExcelFile = "C:\Users\bt\Desktop\Prisberegner(Test version 5)i.xlsm"
ExcelSheet = "Rådata"
GoExcel.Open(ExcelFile, ExcelSheet)
Dim bRow As BOMRow
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")
Dim docPropertySet1 As PropertySet
docPropertySet1 = rDoc.PropertySets.Item("User Defined Properties")
'item , part number, qty, description, G_L (Custom), Raw material, Status (Custom)
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "A" & row) = bRow.ItemNumber
Catch
End Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "B" & row) = docPropertySet.Item("Part Number").Value
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "C" & row) = bRow.ItemQuantity
Catch
End Try
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "D" & row) = docPropertySet.Item("Description").Value
Catch
End Try
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "E" & row) = docPropertySet1.Item("G_L").Value
Catch
End Try
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "F" & row) = docPropertySet1.Item("Raw Material").Value
Catch
End Try
Try
GoExcel.CellValue(ExcelFile, ExcelSheet, "G" & row) = docPropertySet1.Item("Status").Value
Catch
End Try
debug("Item nr. " & bRow.ItemNumber)' & "part number " &docPropertySet.Item("Part Number").Value & "qty " & bRow.ItemQuantity & "description " & docPropertySet.Item("Description").Value & "Length " & docPropertySet1.Item("G_L").Value & "Raw Material " & docPropertySet1.Item("Raw Material").Value & "Status " &docPropertySet1.Item("Status").Value)
row = row + 1
If Not bRow.ChildRows Is Nothing
Call ExportToExcel(bRow.ChildRows)
End If
Next
End Function
End Class