title: Call a solidworks macro from a sub and pass global variables
body: <p>In Solidworks I record two macros.</p>
  
  <p>Macro 1 is empty:</p>
  
  <pre><code>Dim swApp As Object
  
  Dim Part As Object
  Dim boolstatus As Boolean
  Dim longstatus As Long, longwarnings As Long
  
  'added code
  Dim distance_of_second_plane
  'end of added code
  
  Sub main()
  
      Set swApp = _
      Application.SldWorks
  
      Set Part = swApp.ActiveDoc
      'added code:  here I want to call the second macro and send it distance_of_second_plane, and have it use that value
       distance_of_second_plane = .05
       '.. now what?
  
      'end of added code, don't know what to add.
  
  End Sub
  </code></pre>
  
  <p>Macro 2 does something that requires data from macro 1:</p>
  
  <pre><code>Dim swApp As Object
  
  Dim Part As Object
  Dim boolstatus As Boolean
  Dim longstatus As Long, longwarnings As Long
  
  Sub main()
  
      Set swApp = _
      Application.SldWorks
  
      Set Part = swApp.ActiveDoc
      boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
      Dim myRefPlane As Object
      Set myRefPlane = Part.FeatureManager.InsertRefPlane(8, 0.05334, 0, 0, 0, 0)
      Part.ClearSelection2 True
  
  End Sub
  </code></pre>
  
  <p>these macros are of course saved in different files.  How do I call the second from the first, passing in the data from the first, and using it in the second?</p>
  
  <p>things I`ve tried:   <a href="http://support.microsoft.com/kb/140033" rel="nofollow noreferrer">http://support.microsoft.com/kb/140033</a>,  <a href="http://www.cadsharp.com/macros/run-macro-from-another-macro-vba/" rel="nofollow noreferrer">http://www.cadsharp.com/macros/run-macro-from-another-macro-vba/</a>, <a href="https://stackoverflow.com/questions/9908872/vba-module-that-runs-other-modules-solved">VBA module that runs other modules</a>, <a href="https://stackoverflow.com/questions/2804327/call-a-subroutine-from-a-different-module-in-vba">Call a Subroutine from a different Module in VBA</a></p>
  
  <p>all of them are problematic.  I'll give details of the errors I get if asked for them.</p>