That is inserting a BOM into a drawing document (i.e. a .slddrw file). I want to insert a BOM into an assembly file (i.e. a .sldasm file). The code I included above uses this method: InsertBomTable. I just realized that it is technically obsolete, but the current version (InsertBomTable2) does the same thing. Additionally, the example given for using the current method throws an error on the line after the BOM was supposed to be created because the BOM failed to be created and swBOMAnnotation is empty.
This works for me... InsertBomTable3 exists also!
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swBOMAnnotation As SldWorks.BomTableAnnotation
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 = "\\Server\path\to\bom-standard.sldbomtbt"
BomType = swBomType_TopLevelOnly 'For Top Level
'BomType = swBomType_PartsOnly 'For Parts Only
Configuration = ""
Set swBOMAnnotation = swModelDocExt.InsertBomTable3(TemplateName, 0, 0, BomType, Configuration, False, swNumberingType_Detailed, True)
This is just an anecdote, I can't see what is wrong with the code that you posted, but maybe it is useful information. The following is from a macro that I use for exporting BOMs to excel from assembly models.
Set swBomTable = swModel.Extension.InsertBomTable2(pathToBomTemplate, 0, 0, swBomType_e.swBomType_Indented, "Default", False)
I don't recall if passing an empty string argument for the configuration worked for me. This might be why I chose to use "Default" in that example; I would certainly prefer not to force the assembly to contain a specific named configuration in order for the macro to work.
Edit: Actually, in the link that you posted, the (unmarked) correct answer was that the OP had not specified a configuration.
Evidently, that's correct. Specifying the configuration creates the correct table.
I should note that there was initially a typo in my template path which is what was causing the table to be empty initially. Correcting that, but leaving the configuration specified as an empty string results in an empty table being created.