4 Replies Latest reply on Nov 1, 2017 4:24 PM by Rebecca Bemrose-Fetter

    VBA Macro: Delete BOM table

    Rebecca Bemrose-Fetter

      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

        • Re: VBA Macro: Delete BOM table
          Alex Burnett

          One syntax change:

          Change the select line to    swAnn.Select3 False, Nothing   parenthesis are only used when you set the return value of the function.

           

          Next: make sure your swBOMtemp path is set to the full path C:\FOLDER\TEMPLATENAME.SLDBOMTBT

           

          This should get you squared away.

            • Re: VBA Macro: Delete BOM table
              Rebecca Bemrose-Fetter

              1-58NMRGB wrote:

               

              One syntax change:

              Change the select line to swAnn.Select3 False, Nothing parenthesis are only used when you set the return value of the function.

               

              Next: make sure your swBOMtemp path is set to the full path C:\FOLDER\TEMPLATENAME.SLDBOMTBT

               

              This should get you squared away.

              Thanks for looking at it, Alex.

               

              I do have the template path set to show the full path. I just removed it for privacy reasons.

               

              The other change was my mistake - I had used parenthesis so I could get a return value to use in a Debug.Print statement. That's how I know the Select3 command is failing to actually select the table. I deleted the Debug.Print statement and the return value for the purposes of this post, but I missed the parenthesis.

               

              Any other thoughts? Your suggested changes don't help.