SOLIDWORKS macro is the most common way to automate and extended the functionality of SOLIDWORKS via its API. 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.

Browse the errors list to find the most common solutions.

Click link to get the detailed description of the issues, its cause and the steps to resolve the problem.

Errors List

  • Run-time Error ‘91’: Object variable or With block variable not set
  • Compile Error: Can’t find project or library
  • Run-time error ‘424’: Object required
  • Run-time error ‘13’: Type mismatch
  • Compile Error: User-defined type not defined
  • Run-time error ‘438’: object doesn’t support this property or method
  • Run-time error ‘429’: ActiveX component can’t create object
  • Run-time Error ‘5’: Invalid procedure call or argument
  • Compile error: The code in this project must be updated for use on 64-bit systems is displayed. Please review and update Declare statements and then mark item with the PtrSafe attribute
  • Cannot Open (for VBA macros)
  • Compile error: Invalid outside procedure error
  • SolidWorksMacro doesn’t contain a definition for ‘swApp’ (VSTA)
  • Cannot open (for VSTA macros)

Fixing the Cannot Open error when running the VSTA macro (C# or VB.NET)

Fixing the inconsistency of sketch segments (line, arcs, etc) or sketch points creation in the macro

Fixing the Cannot Open error when opening or running the macro stored under the long projects structure

Fixing the error when running or editing the legacy macro in swb format

Fixing the error when selections in the macro are not consistent

Fixing the Run-time Error '5' - Invalid procedure call or argument error when running a macro which is using the title of the model (e.g. inserting the note, linking the custom property value, generating new file name for exporting)

Fixing the macro which doesn't work if it is run from the Tools->Macro->Run menu in SOLIDWORKS but works correctly if opened in the VBA editor and executed via F5 or by clicking green arrow

Fixing the macro which fails when run on old (not the latest) version of SOLIDWORKS and Run-time error '438' - object doesn't support this property or method or Run-time error '445' - object doesn't support this action error is displayed

Fixing Run-time error '424' - Object required for macros which work correctly independently but failed to work when merged to one

Fixing Can't find project or library error in legacy macro

Fixing the Run-time Error '91' - Object variable or With block variable not set when macro is working with the components in the assembly

Fixing the Compile error - The code in this project must be updated for use on 64-bit systems when macro is utilizing Windows API functions

Fixing the error in the macro which connects to database (e.g. SQL, MySql, Oracle, MS Access etc.) or any other data source and doesn't read/write values or displays error

Fixing the compile error of VSTA macro when the code is copied from the example

Fixing the Run-time Error '91' or Run-time error '13' when running the macro

Fixing the Compile error - Invalid outside procedure error when placing the long text into the VBA macro variable

How to fix Runtime error 429 in VBA macros