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.
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.
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.