1 Reply Latest reply on Aug 14, 2017 3:53 PM by Alex Burnett

    How to use macro save Table as txt file?

    Richard Zhang

      Question: The following table is with assembly model (NOT on detail drawing!), how to use macro save as txt file?



        • Re: How to use macro save Table as txt file?
          Alex Burnett

          Can you try this and see how it works for you? I just created a simple assembly and a small table and it seems to work for me. It defaults the save point to the user's desktop.


          Sub main()

              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swAnno As SldWorks.Annotation

              Dim swTable As SldWorks.TableAnnotation

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Debug.Print "File = " & swModel.GetPathName


              Set swAnno = swModel.GetFirstAnnotation

              Do While Not swAnno Is Nothing

                  If swAnno.GetType = swAnnotationType_e.swTableAnnotation Then

                      Set swTable = swAnno.GetSpecificAnnotation

                      Debug.Print "  " & swAnno.GetName

                      swTable.SaveAsText Environ("USERPROFILE") & "\Desktop\" & swModel.GetTitle() & "_" & swAnno.GetName & ".txt", vbTab

                  End If

                  Set swAnno = swAnno.GetNext


          End Sub


          Edit: Added bold text to work with multiple tables in same file