How to run solidworks vba macros from matlab?

I am trying to run a VBA macro from a .m file. I've been able to successfully get Solidworks to start and open a part using:
swApp=actxserver('SLDWORKS.application')
set(swApp, 'Visible', true);
O1 =invoke(swApp,'OpenDoc','[file location]',1);
However, when trying to run a macro using the code below, the macro doesn't seem to run. No error is returned, but the macro hasn't run.
S1=invoke(swApp ,'RunAttachedMacro','Macro2.swp', 'Macro21', 'main')
Is there a problem in the way I'm calling the macro from matlab?
Thanks!

Answers (1)

Hi Anish,
You're using "invoke" to call methods on the SolidWorks application object. The usage of "invoke" seems correct, but there might be an issue with the parameters you're passing to the "RunAttachedMacro" method.
Ensure the following:
  1. The file path to the macro is correct and accessible by MATLAB.
  2. The macro file name, module name, and procedure name are all correct.
  3. The SolidWorks application has permissions to execute macros (consider security settings).
  4. Another alternative is to use "run" method.
Hope this helps.

Categories

Products

Release

R2021a

Asked:

on 3 Feb 2022

Answered:

on 18 Jan 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!