I have multiple assembly files I want to generate BOMs for. Instead of creating the BOMs in a drawing file (which hasn't been created yet), I would like to generate a BOM within the assembly file instead using a macro. I can then use #Task to batch this macro and export all the BOMs into an excel file too.
Below is a bit of code I customised to generate a BOM from an active assembly document.
For some reason I'm getting '91' error highlighted in the screenshot below. What could be causing this?
Any advice would be much appreciated.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.AssemblyDoc
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swBOMAnnotation As SldWorks.BomTableAnnotation
Dim swBOMFeature As SldWorks.BomFeature
Dim swNote As SldWorks.Note
Dim boolstatus As Boolean
Dim BomType As Long
Dim Configuration As String
Dim TemplateName As String
Dim nErrors As Long
Dim nWarnings As Long
Set swApp = Application.SldWorks
' Open assembly document
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
' Insert BOM table
TemplateName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\lang\english\bom-kelvin_test_template.sldbomtbt"
BomType = swBomType_PartsOnly
Configuration = "Default"
Set swBOMAnnotation = swModelDocExt.InsertBomTable3(TemplateName, 0, 1, BomType, Configuration, False, swNumberingType_Detailed, True)
Set swBOMFeature = swBOMAnnotation.BomFeature 'problem with this line*