See more issues and resolutions

Symptoms

Selecting the SWBasic Macros (*.swb)
Selecting the SWBasic Macros (*.swb)

Legacy SOLIDWORKS macro in *.swb format failed when edited with a ‘Compile Error: User-defined type not defined’ error. It usually runs correctly if run from the Tools->Macro->Run menu:

Compile Error: User-defined type not defined
Compile Error: User-defined type not defined

Cause

SWBasic macros are scripts stored in ASCII format (i.e. plain text) which cannot store any references information. SOLIDWORKS types are defined in the SOLIDWORKS type libraries which ae not referenced by default in SWBasic macros.

Resolution

  • Open the macro for editing (Tools->Macro->Edit)
  • Navigate to the Tools->References menu
References menu in VBA editor
References menu in VBA editor
  • Check all SOLIDWORKS type libraries
SOLIDWORKS Type Libraries in the VBA References dialog
SOLIDWORKS Type Libraries in the VBA References dialog
  • Save the macro in *.swp format