Blog

Blog2023-10-15T01:29:24-04:00

Fix “Compile error : Can’t find project or library”

You’ve written your first “serious” SolidWorks API macro. You’re ready to share with your co-workers. You fire up your email, attach the macro, and click Send. Expecting an avalanche of compliments, you instead get several responses from your co-workers telling you that the macro doesn’t run. “Doesn’t run?! How can that be? It runs fine on my computer!” You ask for a screenshot of the error and this is what they send you:

Compile error: can't find project or library

Has this ever happened to you? Maybe not in this exact scenario, but the infamous “Compile error: Can’t find project or library” error message eventually befalls every API programmer trying to share their VBA handiwork with others. Fortunately, it isn’t that hard to fix.

The Cause

When you write code with the SolidWorks API, you constantly use what are called “API calls”. These are the functions you use in your code to execute commands in SolidWorks. Visual Basic for Applications, however, can’t make heads or tails of these API calls unless your code references the appropriate libraries. By libraries I mean the .dll and .tlb files created by SolidWorks Corporation that define each SolidWorks API call. Some of the more common ones include:

  • SolidWorks 20XX Type Library
  • SolidWorks 20XX Commands type library
  • SolidWorks 20XX Constant type library
  • SolidWorks 20XX Extensibility type library
  • Etc.

You can see this list if, while in the VB Editor, you go to Tools–>References. If you click on one of these listings, you’ll also see the file path for the type library. When you create a new macro on your computer, the macro looks at these paths for the references. The problem occurs when you transfer that macro to another computer that has these references in a different location. If your macro can’t locate a reference, you may see the word “MISSING” before the missing reference, but not necessarily.

The Solution

At the computer where the error is occurring:

  1. Open up the macro in the Visual Basic Editor.
  2. Go to Tools–References. If this is grayed out then the macro is still running. Stop it by going to Run–>Reset.
  3. Locate the references with “MISSING” in the names. (Example) If you do not see any, then skip to the second set of instructions below.
  4. Uncheck the missing references.
  5. For your version of SOLIDWORKS, locate the references with the equivalent names and check them. If the missing references correspond to the version you are using, then first click OK on the References dialog and then re-open the references dialog.
  6. Click OK to exit the references dialog.
  7. Test the macro.

In this second set of instructions, you will copy the contents of the problematic macro to a brand new macro created on this computer. (This is the method demonstrated in the video at the beginning of the post.)

  1. Leave the VB Editor open and return to SolidWorks. Create a new macro by going to Tools–>Macro–>New.
  2. Back in the VB Editor, both the problematic macro and the new macro should be visible in the Project Explorer in the top left.
  3. Delete out the existing module in the new macro by right clicking on it and choosing Remove . Click No if you are asked whether you want to export the module.
  4. One by one, drag all of the modules from the problematic macro into the new macro’s project name.
  5. Test the new macro on this computer. You should not encounter an error.

Finally, don’t forget that this is just one of the many compile or run-time errors you can run into while programming with the SolidWorks API using VBA. Our FREE SolidWorks API Debugging Tips PDF contains descriptions and solutions for 14 other common errors. Grab it now and keep it handy—you won’t regret it!

Conquering compile errors,
Keith

Did you find this post helpful? Keep up with future CADSharp.com content, webinars, and special offers by signing up for our newsletter.

By |April 16th, 2013|1 Comment

SolidWorks World 2013 : API Presentations

SolidWorks World 2013, hosted at Disney World in Orlando, is right around the corner. This year in particular looks like a great year for SolidWorks API learners and enthusiasts. If you’re attending, below is a list I’ve compiled of all presentations related to the SolidWorks API. If you have the opportunity, definitely join me on Tuesday at 4:30 for my presentation, “The 99 Must-Know Members of the SolidWorks API” (the same one I delivered last year). Stop by afterward and say hello—It would be great to meet you!

API for the Beginner

Monday, 10:30 AM – 12:00 PM
Tom Cote, Applied CAD Solutions, LLC
Step through different ways to create, get info from the web, edit, test & document a macro as well as linking the macro to an icon in SolidWorks. This session is designed for the person that has no programming experience.

Features and Capabilities of the SolidWorks Costing API

Monday, 1:30 PM – 2:30 PM
Daniel Seaman, SolidWorks Corp
Gain an introduction to the SolidWorks Costing API covering its capabilities and limitations using real-world case studies. Use the API to compare the cost implications of using different manufacturing processes and extract detailed information about the tools, materials, and time required to make a part.

Get Started with Visual Basic.NET Macros

Monday, 4:30 – 6:30 PM
Mike Spens, SolidWorks Corp
Learn how to automate SolidWorks using the Visual Studio for Applications (VSTA) macro environment. In this hands-on session, attendees examine the benefits of VB.NET versus VBA, and take away the handy utility they create.

Automating Weldments with API

Tuesday, 1:30 – 2:30 PM
Cody Armstrong, Digital Dimensions, Inc.
Automate weldment part and drawing design using the SolidWorks API.

Visual Basic® for Applications 7: Getting SolidWorks Macros Ready for 64-Bit

Tuesday, 10:30 AM – 12:00 PM
Frank Lindeman, SolidWorks Corp
Hear an introduction to the language changes of Visual Basic for Applications 7 in SolidWorks 2013, supporting 64-bit. This presentation will outline scenarios to adapt existing macros using external Windows® and ActiveX® controls dlls for use with SolidWorks 2013, while keeping them backward-compatible.

Macros for the Masses – Beginning VSTA

Tuesday, 1:30 – 2:30 PM
Jerry Winters, PDMI, Inc.
Join the ranks of those who turbo-charge their SolidWorks installations by learning VSTA yourself. On its own, SolidWorks can be used to design amazing things. When we learn how to write macros (and not just record them), we can design better, faster, and more accurately.

The 99 Must-Know Members of the SolidWorks API

Tuesday, 4:30 – 6:00 PM
Keith Rice, CADSharp.com
Gain a glimpse of what’s important and what’s not, covering many aspects of part, assembly, and drawing automation using a realistic case study. The SolidWorks API is huge. Like any language, however, you only need to know 5 percent of the words to accomplish 95 percent of what you need.

Design with the API in Mind

Wednesday, 1:30 – 2:30 PM
Jerry Winters, PDMI, Inc.
Learn the tools and techniques that best support downstream API efforts. SolidWorks gives us an amazing number of design tools we can use to create our models. But if we plan on using the SolidWorks API to create custom solutions for our models, not all design tools are created equal.

Finally, if you aren’t attending SolidWorks World but would still like to see presentations that were recorded, or at least download PowerPoint slides, be sure to visit the presentation archive after a few weeks. Here you can also watch API-related presentations from the past few years.

Hope to see you in Orlando!

Want to keep up with future CADSharp.com content, webinars, and special offers? Sign up for our newsletter.

By |January 16th, 2013|0 Comments

How To Copy, Clean, & Use API Help Examples

I received a great question from one of my newer customers the other day: “Why can’t I ever seem to get an API Help example to work right after copying and pasting it into the Visual Basic Editor?” The answer, simply, is that the text is rarely transferred over perfectly. As demonstrated in the tutorial below, cleanup is involved. I also take it a step further and show you some tips for improving the readability of the code. Finally, I explain how to deal with errors that occur when trying to run the macro from Tools–>Macro–>Run.

For those of you who like to remove every last unnecessary line of code: you can also remove the enumeration declarations in the beginning. They exist in many API Help examples but they really serve no purpose since by default the SolidWorks constants type library is automatically referenced.

Thanks for visiting our blog and merry Christmas!

Keith

Want to keep up with future CADSharp.com content, webinars, and special offers? Sign up for our newsletter.

By |December 17th, 2012|2 Comments
Go to Top