See more issues and resolutions

Symptoms

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

Alternatively non-SOLIDWORKS declarations can be highlighted (such as Left or Mid functions)

Can't find project or library error on Left function in VBA
Can't find project or library error on Left function in VBA
  • If the libraries were never selected in the macro the Compile error: user-defined type not defined can be displayed.
Compile error: user-defined type not defined
Compile error: user-defined type not defined

Cause

  • Macro is pointing to older versions of SOLIDWORKS type libraries and cannot resolve them automatically. As the result the libraries are marked as MISSING.

  • SOLIDWORKS type libraries were never selected or were explicitly deselected in the macro (this usually happens when macro is converted from *.swp macro)

Resolution

  • Open the macro for editing via Tools->Macro->Edit menu
  • Navigate to Tools->References menu in the VBA editor
  • Select the SOLIDWORKS type libraries as shown below. If libraries cannot be found in the Available References list use Browse… button and find the sldworks.tlb, swconst.tlb, swcommands.tlb in the installation folder of SOLIDWORKS.
Required SOLIDWORKS type libraries
Required SOLIDWORKS type libraries
  • If libraries are selected or MISSING keyword is present it is required to force update the references by following the steps below:
List of missing references in VBA macro
List of missing references in VBA macro
  • Uncheck all of the libraries which are referencing SOLIDWORKS. (including libraries with MISSING keyword next to them)
  • Click OK
  • Open the same dialog again and check corresponding SOLIDWORKS libraries. Those are usually available in the references list. If not you can use ‘Browse…’ button to manually select the libraries from the SOLIDWORKS installation folder

Alternatively you can copy paste all the code to newly created macro.