Run attached VSTA macro

Is it possible to run VSTA macro, which is attached in the design binder, from a second VBA macro, using the RunAttachedMacro method?

Since the RunAttachedMacro takes the macro name, module name, and procedure name as parameters, I tried setting up my vsta macro like this:

Partial Class SolidWorksMacro
Public Sub main()

    MsgBox("To dela")
End Sub
''' <summary>
''' The SldWorks swApp variable is pre-assigned for you.
''' </summary>
Public swApp As SldWorks

End Class

Module HandlerModule
Dim macro As New SolidWorksMacro

Public Sub main()
    macro.main()

End Sub

End Module

Unfortunatly unsuccessful.

Posnetek zaslona 2024-05-31 212911

What’s the purpose of attaching the macro file into the model? How could you run it on SW?

Maybe it’s possible if you attach an executable macro file.

You can. I would not do that. It looks like a virus.

Here’s how you do it through:

  • Write an add-in that downloads the file from the binder.
  • Load the DLL in memory.
  • Invoke the entry point by supplying the swApp instance from your add-in.