Inserting a BOM using API

Good Monday Friends,

I'm trying to insert a BOM into my drawings using a macro. I found an example in the solidworks help. Unfortunately, the program keeps getting caught up at a certain line and I have no clue why. I am using solidworks 2013, so the code should be working. I've included my code so it may be perused. Any help would be greatly appreciated.

Thanks,

Trevor

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFeatMgr As SldWorks.FeatureManager

Dim swView As SldWorks.View

Dim swBomAnn As BomTableAnnotation

Dim swBomFeat As SldWorks.BomFeature

Dim anchorType As Long

Dim bomType As Long

Dim configuration As String

Dim tableTemplate As String

Dim Names As Variant

Dim visible As Variant

Dim boolStatus As Boolean

Dim swDraw As SldWorks.DrawingDoc

Dim swSheet As SldWorks.Sheet

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swFeatMgr = swModel.FeatureManager

Set swDraw = swModel

Set swSheet = swDraw.GetCurrentSheet

'Select View

swModel.ClearSelection2 True

Set swView = swDraw.GetFirstView

'Insert BOM Table

anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight

bomType = SwConst.swBomType_e.swBomType_TopLevelOnly

swModel.ClearSelection2 True

configuration = "" '"Default"

tableTemplate = "" '"C:\KMI-Vault\Admin Files\SW - Templates\TABLES\kTable.sldbomtbt"

Set swBomAnn = swView.InsertBomTable2(False, 0, 0, anchorType, bomType, configuration, tableTemplate)

Set swBomFeat = swBomAnn.BomFeature<==========Error 91: Objuect Variable or With block variable not set.

Names = swBomFeat.GetConfigurations(False, visible)

visible(0) = True

boolStatus = swBomFeat.SetConfigurations(True, visible, Names)

swFeatMgr.UpdateFeatureTree

End Sub

SolidworksApi macros