7 Replies Latest reply on Dec 19, 2016 10:10 AM by Jason Reese

    Save Drawing BOM to excel Macro - issue only saving one BOM

    Jason Reese

      Hello.. I'm pretty new to macros.. I took a couple macros that I found and merged them together.. Currently, I can get it to select all the BOM's in a drawing.. but it only saves one BOM.. if there is more than one in a drawing. I need it to save every BOM in a drawing. My thought was.. if I could get it to save with the Feature Name ex.(Bill of Materials1) .. It would save each one.. Also, any ideas on Merging all the saved CSV files into one Excel document. I was going to write a macro to do this in Excel.. If I could write that into the Macro too.. That would be great.. Thanks


      If there is a better way to select the Bill of Materials.. like a wildcard - selecting all without listing 1 - 2 - 3 and so on.

        • Re: Save Drawing BOM to excel Macro - issue only saving one BOM
          Artem Taturevych

          Hi Jason,


          You need to traverse the tree and find all tables by type. Your have this function in your macro which is called TraverseFeatureTree


          So you need to move this bit

              CSVFile = RenameBomToCSV


              retval = swTableAnn.SaveAsText(CSVFile, ",")

              SaveCSVAsXLS CSVFile


          into the marked area below:


                          If FeatureName = "Bill of Materials1" Then

                              swFeature.Select True


                         End If


                          If FeatureName = "Bill of Materials2" Then

                              swFeature.Select True


                         End If


          You also need to get the table from the feature rather than from the selection (you do not need to select the table). So this would look something like that:


                  Dim swTableFeat As Object

                  Set swTableFeat = swFeature.GetSpecificFeature2


                  Dim swTableAnn As SldWorks.TableAnnotation

                  Set swTableAnn = swTableFeat.GetTableAnnotations()(0)


          I have noticed that your macro is doing the batch export. If you want you may try #TASK which has a task to export all specified tables from the files in the folder. It also allows to specify the custom naming, types as well as use wildcard to find the tables by name. You need to specify the 'drawings' filter to process just drawings.