0

Solidworks では、2 つのマクロを記録します。

マクロ 1 は空です:

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

マクロ 2 は、マクロ 1 からのデータを必要とする処理を行います。

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

もちろん、これらのマクロは別のファイルに保存されます。最初から 2 番目を呼び出し、最初からデータを渡し、それを 2 番目で使用するにはどうすればよいですか?

私が試したこと: http://support.microsoft.com/kb/140033http://www.cadsharp.com/macros/run-macro-from-another-macro-vba/他の実行する VBA モジュールmodulesVBA の別のモジュールからサブルーチンを呼び出す

それらのすべてが問題です。求められた場合は、取得したエラーの詳細を提供します。

4

2 に答える 2

1

共通のメソッドをカプセル化する別のモジュールを作成できます。次に、そのモジュールへの参照を追加し、Macro1 と Macro2 サブルーチンの両方から呼び出します。

たとえば、Macro1 では次のようになります。

  1. プロジェクト エクスプローラーで、Modules フォルダーと Insert-Module を右クリックし、Module1 に名前を付けます (または任意の名前を付けます)。

ここに画像の説明を入力

  1. Module1 でサブルーチンを作成し、InsertPlane (または意味のある名前) という名前を付け、実行する必要があることを達成するために必要なパラメーターを使用してサブルーチンを構築します。

    Sub InsertPlane(ByRef swApp As Object, ByVal distance As Double)
    
        'enter your code here, the parameters passed to InsertPlane can be whatever you need
        'to do what the method needs to do.
    
    End Sub
    
  2. マクロの main() メソッドで、必要に応じて InsertPlane() メソッドを呼び出します。

    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 = 0.05
    
     'example of calling the subroutine
     boolstatus = Module1.InsertPlane(swApp, distance_of_second_plane)
    
    End Sub
    
  3. モジュールはエクスポートおよびインポートできるため、他のマクロで再利用できます。これを行うには、Module1 のプロジェクト ツリーで右クリックし、ファイルをエクスポートします。同様に、Modules フォルダーを右クリックしてモジュールをインポートできます。

お役に立てれば。

于 2014-08-25T21:54:14.153 に答える