4 Replies Latest reply on Jul 10, 2017 8:13 AM by Ivana Kolin

    How to use RunMacro?

    Yong Ning

      Help me. how to use RunMacro in Excel VBA

       

      Result is  see image.

       

      aa.jpg

       

       

      SwApp.RunMacro FilePath, "a.swp", "aaa" , don't sub aaaa

      ************************************************************************

      in excel vba  code is

      Private Sub aaa()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = GetObject(, "SldWorks.Application")

             Set SwModel = SwApp.ActiveDoc

          

         Dim FilePath

             FilePath = ThisWorkbook.Path & "\" & "a.swp"

             Debug.Print FilePath

             'SwApp.RunMacro FilePath, "a.swp", "aaa"

             SwApp.RunMacro FilePath, "a1", "aaa"

          

      End Sub

       

       

      in solidworks API

       

       

       

      Private Sub aaa()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = Application.SldWorks

             Set SwModel = SwApp.ActiveDoc

         Dim SwSelMgr As SelectionMgr

             Set SwSelMgr = SwModel.SelectionManager

         Dim SwDispDim As DisplayDimension, SwDim As Dimension

             Set SwDim = SwModel.Parameter("D1@Sketch1")

             Debug.Print SwDim.FullName

             MsgBox SwDim.FullName & "=" & SwDim.Value

             Stop

      End Sub

       

       

       

      2017 SOLIDWORKS API Help - Microsoft Visual Studio Tools for Applications Requires Microsoft .NET Framework 3.5  http://help.solidworks.com/2017/English/api/sldworksapiprogguide/GettingStarted/VSTA_Dependency_on_DotNet_3Dot5.htm

        • Re: How to use RunMacro?
          Yong Ning

          a.swp runmacro b.swp, result is true

           

           

          in a.swp, code is

           

           

          Sub main()

          Set swApp = Application.SldWorks

          Dim filename As String

          filename = swApp.GetCurrentMacroPathName

          filename = Left(filename, InStrRev(filename, "\")) + "b.swp"

          boolstatus = swApp.RunMacro(filename, "b1", "main")

          End Sub

           

           

          In b.swp, code is

           

          Sub main()

              Dim swApp As SldWorks.SldWorks

              Set swApp = Application.SldWorks

              MsgBox "ffffffffffffffff"

              swApp.SendMsgToUser "RunMacroSub1:main() called"

          End Sub

          • Re: How to use RunMacro?
            Ivana Kolin

            change

            Private Sub aaa

            to

            Public Sub aaa

              • Re: How to use RunMacro?
                Yong Ning

                in excel, result is false

                 

                 

                false.jpg

                 

                 

                 

                 

                Public Sub aaa()

                   Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                       Set SwApp = GetObject(, "SldWorks.Application")

                       Set SwModel = SwApp.ActiveDoc

                      

                   Dim FilePath

                       FilePath = ThisWorkbook.Path & "\" & "b.swp"

                       Debug.Print FilePath

                 

                 

                       tmp = SwApp.RunMacro(FilePath, "b1", "main")

                      

                End Sub

                 

                 

                 

                Sub aa()

                   Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                       Set SwApp = GetObject(, "SldWorks.Application")

                       Set SwModel = SwApp.ActiveDoc

                      

                   Dim FilePath

                       FilePath = ThisWorkbook.Path & "\" & "b.swp"

                       Debug.Print FilePath

                       tmp = SwApp.RunMacro(FilePath, "b1", "main")

                       Stop

                      

                End Sub