1 Reply Latest reply on Jul 11, 2017 5:48 PM by Nilesh Patel

    RunMacro2→deliver function (parameter)?

    Yong Ning

      follow code don't use function parameter ?

      don't  RunMacro.swp parameter → deliver → RunMacroSub.swp



      Help me. swApp.RunMacro2 → deliver parameter → function aa(parameter1,parameter2,parameter3)

      Function aa(Str)

          MsgBox Str

      end function




      2015 SOLIDWORKS API Help - RunMacro2 Method (ISldWorks)  http://help.solidworks.com/2015/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~runmacro2.html





      ' RunMacro.swp


      Option Explicit

      Dim swApp As SldWorks.SldWorks

      Dim boolstatus As Boolean

      Sub main()

      Set swApp = Application.SldWorks

      Dim runMacroError As Long

      boolstatus = swApp.RunMacro2("f:\test\RunMacroSub.swp", "RunMacroSub1", "main", swRunMacroUnloadAfterRun, runMacroError)

      End Sub







      ' RunMacroSub.swp'


      Sub main()

      Set swApp = Application.SldWorks

      swApp.SendMsgToUser "RunMacroSub1:main() called."

      End Sub

        • Re: RunMacro2→deliver function (parameter)?
          Nilesh Patel

          Hi Yong,


          Attached macros work fine for me as long as you specify correct macro path, module name and procedure name.


          You can only call Sub or Function which has no arguments using swApp.RunMaco or swApp.RunMacro2. Your function 'aa' has an argument 'Str' and therefore it won't work. Run your macro step by step and see the value of 'runMacroError', this will give you an idea of what the error is.