Getting Errors when using downloaded Macros?

Errors when running downloaded SolidWorks macros (Visual Basic 6) can be caused by many different issues, depending on the macro and which version of SolidWorks being used.  Here are some general points that may help.

Reference Libraries
Check reference libraries associated with the macro. These can be accessed by opening the macro through SolidWorks API editor (edit macro function), then going to pulldown Tools>Reference Libraries. If any of the listed libraries have the word MISSING in front of them, remove their check mark. You may need to replace it with a similarly named reference library that is included on your system. For example, if “SolidWorks 2008 Object Library” is missing and you are running SolidWorks 2007, then look for and activate the library named something like “SolidWorks 2007 Object Library”. SolidWorks may be able to do this automatically, but on many computer systems, you will need to manually make this edit, particularly if using a macro made on a version of SolidWorks newer than you are using.

Conversely, errors can be caused by having conflicting libraries loaded at the same time (i.e., having too many libraries).  No errors will appear in the reference library list.  If you are certain the correct library is loaded already, trying removing other SolidWorks related libraries one by one until the issue is resolved.

Also, the correct reference library may not be loaded at all. Research the line of code causing the error to make sure the correct reference library is loaded to support those instructions.

Additionally, if a macro was made on a newer version of SolidWorks than what you are currently using, its instructions may not be supported at all on the system running the older version of SolidWorks. In this case, you will need to find an equivalent API method for the older SolidWorks version, if one exists.

If the macro does not use Forms, a quick way to make sure you are using current reference libraries is to simply cut and paste the complete code from the existing macro file to a new one created fresh on your system. Often, this will fix any mismatched reference libraries, but it might still require research to make sure all the necessary reference libraries are loaded for that macro.

Sub-Modules
When executing the macro, make sure you specify the “Main” sub-module as the starting point. This is the section of code following the line “Sub Main ()”. Most macros are set up with Main as their starting sub-module. This is usually a fix if you are having issues associating your macro with an icon on a Toolbar, assigning a shortcut key, or trying to execute the macro from within another macro.

If the macro does not have a Main sub-module, then you may need to study the macro to discover which sub-module is meant as the starting point.

Copying code from online or plain text source
Sometimes when code appears in plain text, such as in a .txt file or from a forum online, it may not be formatted properly. Some of the lines may be too long for the plain text source, so they are line broken. This will disrupt the code, as SolidWorks API will misunderstand the instructions. When copy and pasting code from a plain text source, make sure to go over the code to insure all the lines are properly reconstructed by removing erroneous line breaks.

Sources for help
If issues are still occuring, contact the author(s), if available. Also, make sure to read over the material and examples provided in the SolidWorks API Help file included with SolidWorks. If those do not completely solve the issue, then search over various online forums dedicated to SolidWorks and SolidWorks API support. Many of these forums are listed under Forum Links.  If the search doesn’t resolve the issue, then post a question on those forums detailing the issue and requesting help from other SolidWorks users. You may also contact your VAR, as the issue you are having may actually be a bug or known issue in the SolidWorks API system itself.

Author: fcsuper

As a drafter, mechanical designer and CAD engineer, I've been in the mechanical design field since 1991. For the first 8 years of my career, I was an AutoCAD professional. I utilized AutoLISP and many other AutoCAD customization features to streamline drafting activities for 6+ drafters and designers. I authored several custom functions, one of which was published in the March 1997 issue of Cadalyst Magazine. Since 1998, I've been used SolidWorks non-stop. I've worked to utilize the SolidWorks' user environment to simplify drafting and design activities for 20+ engineers. I've created this website to provide current information about SolidWorks from a variety of contributors. More recently, I am now employed by Dassault Systemes as SOLIDWORKS Sr. Product Definition Manager to improve drawing, annotation and MBD related areas.

2 thoughts on “Getting Errors when using downloaded Macros?”

  1. Matt, Here is an additional comment on the start point for SolidWorks macros.

    When using the Run Macro button on the macro toolbar, you cannot specify the subroutine the macro will start in. In this case, the macro will start in the last public subroutine of the last module inserted into the macro file. To find out which subroutine will automatically start in this manner, open the macro in the macro editor. The module and subroutine that the macro opens in, is where the macro will start.

    You do need to know the start point of the macro if you are going to assign the macro to a toolbar button or keyboard shortcut. Using the above steps will help you discover the proper start point.

Leave a Reply

Your email address will not be published. Required fields are marked *