How to delete a BOM Table from a Part Doc using API?

I would like a macro that can do the following:

1.  Inserts a BOM table into a PART document

2.  Exports it as text

3.  Deletes the table created in step 1

I have done everything successfully except for step 3.  I am pretty sure that I'm close to the correct answer, but I haven't quite got it.  Here's my code (removed some items for clarity).

How the heck does one *get* the table so it can be deleted?  I don't want the user to be required to select it.

Private Sub MyMacro()

 

          Dim swModel As Object

          Dim swBOMTable As Object

          Set swApp = CreateObject("SldWorks.Application")

          Set swModel = swApp.ActiveDoc

     'Set swBOMTable = swModel.Extension.InsertBomTable()

     'retval = swBOMTable.SaveAsText()

'Here is where I think it's going wrong.

'The following code executes, but retval returns FALSE

'How do I select the table automatically so that I can delete it?

          retval = swModel.Extension.SelectByID2("", "BOMFEATURE", 0, 0, 0, False, 0, Nothing, 0)

'The above line always returns FALSE

          swModel.EditDelete

End Sub

SolidworksApi macros