2 Replies Latest reply on Dec 31, 2013 6:37 PM by Poorvesh Mistry

    VB macro to use Excel 2013 data in SolidWorks 2013, to create part & insert parts into assembly

    Poorvesh Mistry

      Currently I am trying create VB macro to fetch data from excel 2013 sheet & use it to

      1) create a part

      2) get data from excel, which defines location of part files & load it in SolidWorks (2013) Assembly

       

      Would be glad if anyone could help me.

       

      Thanks & Regards

      Poorvesh

        • Re: VB macro to use Excel 2013 data in SolidWorks 2013, to create part & insert parts into assembly
          Aj Jones

          Poorvesh,  I haven't tried this with the SolidWorks built in vb macro.  I have done something similar to this with VB.NET if that would help.

          Thanks,

            • Re: VB macro to use Excel 2013 data in SolidWorks 2013, to create part & insert parts into assembly
              Poorvesh Mistry

              Thanks Aj Jones,

               

              Mr. Keith @ Cadsharp.com provided a lot of help towards learning the basics of Macro, VB and connecting SolidWorks with MS Excel.

               

              http://www.cadsharp.com/blog/using-microsoft-excel-with-the-solidworks-api/#comment-805

               

              Following are the content of the SolidWorks Macro

              ————————————————————————————————————————————
              Declare PtrSafe Function PostMessage Lib “user32″ Alias “PostMessageA” (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
              Const WM_QUIT = &H12
              Dim swApp As Object
              Dim Part As Object
              Dim boolstatus As Boolean
              Dim longstatus As Long, longwarnings As Long
              Dim strText As String

              Sub main()
              Dim swApp As SldWorks.SldWorks
              Set swApp = Application.SldWorks

                  Dim xlApp As Excel.Application
              Dim xlWB As Excel.Workbook

                  Set xlApp = New Excel.Application
              xlApp.Visible = False
              Set xlWB = xlApp.Workbooks.Open(“C:\Solidworks-macros\test.xls”)

                  ‘find number of rows with data
              Dim row As Integer
              row = 1
              With xlWB.Worksheets(1)
              While Cells(row, 1).Value  “”
              ‘swApp.SendMsgToUser2 Cells(row, 1).Text, swMbInformation, swMbOk
              strText = Cells(row, 1).Text
              Set Part = swApp.OpenDoc6(strText, 1, 0, “”, longstatus, longwarnings)
              swApp.ActivateDoc2 “b plate_pcs2b.sldprt”, False, longstatus
              row = row + 1
              Wend
              End With

                  ‘clean up
              xlApp.Visible = True
              PostMessage xlApp.hwnd, WM_QUIT, 0, 0

                  Set xlWB = Nothing
              Set xlApp = Nothing
              End Sub
              ————————————————————————————–

               

              Cheers & HAPPY NEW YEAR

               

              Thanks & Regards
              Poorvesh