Fixing the error when running legacy SWBasic (*.swb) SOLIDWORKS macro

Edit ArticleEdit Article
Comments
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

Notifications

All articles and code at CodeStack are now open-source and hosted on GitHub. If you want to contribute by modifying existing articles and code snippets, submitting new ones, reporting errors and bugs etc. please follow this blog post for more information. We appreciate any contribution.


Product of Xarial Product of Xarial