Macros Troubleshooting: Issues And Resolutions

SOLIDWORKS macro is the most common way to automate and extended the functionality of SOLIDWORKS via its APIs. Macros can be developed in-house or downloaded from the different web-sites including SOLIDWORKS forum, 3D Content Central, Code Stack etc. or even recorded from SOLIDWORKS.

But in some cases the macro doesn't work as expected. This is usually one of the following scenarios:
  • Macro which used to work correctly before stopped working.
  • Macro works on some of the workstations but not on the others.
  • Macro works correctly for some models but not the others.
In this article I will go through the most common symptoms of the errors in the macros. Click View Solution link to get the detailed description of the issues, its cause and the steps to resolve the problem.

Legacy macro downloaded from the internet or have been developed in-house some time ago failed o run. Can't find project or library error is displayed and of the SOLIDWORKS declarations are highlighted.

Running the macro which processes the active model or selection produces Run-time Error '91': Object variable or With block variable not set error or 'Run-time error '13': Type mismatch' error or misbehaves in any other way.

Macro doesn't work if it is run from the Tools->Macro->Run menu in SOLIDWORKS. This may produce error like 'Run-time Error '91': Object variable or With block variable not set. Alternatively macro can misbehave or just do not execute any steps. Macro runs correctly if opened in the VBA editor and executed via F5 or by clicking green arrow (run) button from the VBA editor.

Macro creates sketch segments (line, arcs, etc) or sketch points. And in some cases the elements are not created while it works correctly in other cases.

Macro is working with the components in the assembly (e.g. reading/writing properties, materials, working with features etc.). Error 'Run-time Error '91': Object variable or With block variable not set is displayed when macro is run.

VSTA macro (C# or VB.NET) cannot be run and the Cannot Open error is displayed

Macro is using the title of the model (e.g. inserting the note, linking the custom property value, generating new file name for exporting). As the result macro misbehaves (inserting extension twice) or displays the error: Run-time Error '5': Invalid procedure call or argument.

Macros work correctly independently but failed to work when merged to one. Possibly, the error is displayed: Run-time error '424': Object required.

System is updated from SOLIDWORKS older than 2012 to a newer version. Or some legacy macro is run. Macro is utilising Windows API functions (e.g. has browse file/folder dialog, connects to registry, uses windows handles) via Declare Function statement. When started the Compile error: The code in this project must be updated for use on 64-bit systems is displayed

SOLIDWORKS VBA macro is utilizing Document Manager APIs and new license was generated. When generated license is placed into the macro some text highlighted red and Compile error: Invalid outside procedure error is displayed. Macro is inserting static text into the note or custom properties. Text is replaced with new long text. Inserted string is highlighted and macro doesn't run.

Macro should connect to database (e.g. SQL, MySql, Oracle, MS Access etc.) or any other data source (e.g. MS Excel). Macro doesn't read/write values or displays error.

Recently developed macro is run on old (not the latest) version of SOLIDWORKS. When run, Run-time error '438': object doesn't support this property or method is displayed.

Macro is stored in the PDM vault under the long projects structure or the macro is generated on a fly to the secure location (isolated storage) from the API. When macro runs or edits the Cannot Open error is displayed. The macro runs normally from another location.

No comments:

Post a Comment