I'm editing a macro that was written by former colleague. The macro inserts a BOM into an assembly, saves it as a text file, opens it in Excel and does a bunch of stuff for eventual importing into our work tracking software.
My problem is the code to delete the table from the Solidworks Assembly file doesn't work. As best I can tell, the failure is at the Select3 command... the selection fails (returns False). What am I missing, can anyone help?
Here's the abbreviated code:
Sub main()
'Define Active SolidWorks Document
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModExt = swModel.Extension
'Get file path and title of active document
swPathName = swModel.GetPathName
swTitle = swModel.GetTitle
'Assign file path for txt file
exPathName = Left(swPathName, Len(swPathName) - 7) 'remove .sldasm suffix
txtPathName = exPathName + "_raw.txt"
'Get the name of the current configuration being used on assembly
Set swConfigMgr = swModel.ConfigurationManager
conName = swApp.GetActiveConfigurationName(swPathName)
'Specifies SolidWorks BOM template location
swBOMtemp = "[file path removed]"
'Insert BOM to model and rebuild
Set swBOMAnnotation = swModExt.InsertBomTable3(swBOMtemp, 0, 0, swBomType_Indented, conName, False, swNumberingType_Detailed, False)
'Save BOM as text file with "^" separating fields
Set swTable = swBOMAnnotation
ret = swTable.SaveAsText(txtPathName, "^")
'Delete BOM from assembly
Set swAnn = swTable.GetAnnotation
swAnn.Select3(False, Nothing)
swModel.EditDelete
[other stuff happens]
End Sub