Assembly BOM saved as txt or .xls

Have found some code that will create a BOM Table in an assembly, it then exports it as a text file and then deletes the BOM from the assembly.

It works ok except that it creates a new table each time it is run.

I would like to do something similar, but the BOM Table will already exist in the assembly. How do I get the BOM Table so that I can export it out to a text file or even better a .xls file?

thanks Andrew.

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:\templates\parts list.sldbomtbt"
Const OutputPath As String = "C:\"

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swBOMTable = swModel.Extension.InsertBomTable(BOMTemplate, 0, 0, swBomType_e.swBomType_PartsOnly, "")
    Set swTable = swBOMTable
  
    swTable.SaveAsText OutputPath & "BOMTable_" & swModel.GetTitle() & ".txt", "Default" 
    Set swAnn = swTable.GetAnnotation
  
    swAnn.Select3 False, Nothing

    'swModel.EditDelete          'not used in this example.

End Sub

SolidworksApi macros