3 Replies Latest reply on Dec 6, 2016 12:37 PM by Deepak Gupta

    Excel functions in a Macro

    Cad Admin

      Looking to open an spacific excel file, preferably without excel popping up, delete the top row, then sort by a given column. Then save and close, all silently...all from within a solidworks macro.

        • Re: Excel functions in a Macro
          Deepak Gupta

          Try these, change as needed. Make sure you add reference to excel


          Sub main()   

          Dim swApp              As SldWorks.SldWorks

          Dim xlApp              As Excel.Application

          Dim xlWorkbook         As Excel.Workbook

          Dim xlSheet            As Excel.Worksheet   


          Set swApp = Application.SldWorks

          Set xlApp = CreateObject("Excel.Application")

          xlApp.Visible = False

          Set xlWorkbook = xlApp.Workbooks.Open("C:\Users\DEEPAK\Desktop\test.xlsx") 'change file name

          Set xlSheet = xlApp.Worksheets("Sheet1") 'change sheet name



          'Add codes for sorting




          End Sub