1 Reply Latest reply on Aug 20, 2015 8:29 AM by Marc-Xavier Bilodeau

    Executing a Solidworks vba macro from Visual Basic .net

    Tomate Macarron

      Greetings everyone,

      Don't know if someone has had this issue, but I had a hard time figuring out this, so I decided to publish it.

      I searched the forum and the web and din not find any solution, so I decided to post it here. It may help someone.


      So, if you want to execute a Solidworks vba macro via Visual Basic .net here is the trick:


      Imports SolidWorks.Interop.sldworks


           'This is a button

           Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click


              'Just to know if solidworks is already opened:

              Dim opened As Boolean

              If Process.GetProcessesByName("SLDWORKS").GetLength(0) > 0 Then

                  opened = True


                  opened = False

              End If


              'Now, this will open solidworks if it is not already opened:

              Dim app As SldWorks = CreateObject("sldworks.application")

              If app IsNot Nothing Then

                  app.Visible = True

              End If



              'And the way to execute the solidworks macro:

              app.RunMacro("C:\Users\*******\Desktop\Macro1.swp", "Macro11", "Macro_name")


             'The three string are:

             'Macro filepath name

             'Module name

             'Procedure name


      End Sub



      Best regards.