Creating and Exporting BOM to Excel

I am new to API and not sure what is wrong. I have looked at many other scripts and I get an error when running the following code:

 

Dim swapp As SldWorks.SldWorks
Dim swmodel As SldWorks.ModelDoc2
Dim swBOMTable As SldWorks.BomTableAnnotation
Dim swTable As SldWorks.TableAnnotation
Dim swAnn As SldWorks.Annotation
Const bomTemplate As String = "C:\CDT_Design\Templates\BOM CDT.sldbomtbt"
Const OutputPath As String = "\\cvcv0fi24\cdtdrawing\$\Individual Workspace\Amit Bachar"
Dim ConfigName As String

 

Sub main()
Set swapp = GetObject(, "SldWorks.Application")
Set swmodel = swapp.ActiveDoc
ConfigName = swmodel.GetActiveConfiguration.Name
ModelPath = swmodel.GetPathName

Set swBOMTable = swmodel.Extension.InsertBomTable(bomTemplate, 0, 0, swBomType_e.swBomType_Indented, ConfigName)
Set swTable = swBOMTable
swTable.SaveAsText OutputPath & "BOMTable_" & swmodel.GetTitle() & ".xls", vbTab

Set swAnn = swTable.GetAnnotation
swAnn.Select3 False, Nothing

swmodel.EditDelete
End Sub

 

The error is in this line:

Set swBOMTable = swmodel.Extension.InsertBomTable(bomTemplate, 0, 0, swBomType_e.swBomType_Indented, ConfigName)

 

error 424 object required.

 

I have an assembly file open and activated when running this macro. I can read the right configuration in the ConfigName variable.

 

Help will be highly appreciated!

SolidworksApi/macros