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

This error pretends to be about your code, and it isn’t. The VBA editor stops on some innocent built-in function — Date, Left, Format, Trim — and claims it can’t find a library. The real problem sits in the project’s References list: one checked reference is missing on this machine, and its absence breaks name resolution for everything else too.

The fix, in order

  1. Open the VBA editor (Alt+F11), then Tools → References. Look down the checked entries for one starting with MISSING: — that’s the broken reference.
  2. Uncheck the MISSING entry and click OK. In most files nothing actually used it — it was added by another machine or an old add-in — and the code compiles immediately.
  3. Press Debug → Compile to test. If the error is gone, save the file. You’re done; the highlighted function was never the problem.
  4. If something genuinely needs that library, re-add the version present on this PC from the same References list, or install/register the component it belongs to.
  5. Moving between 32-bit and 64-bit Office? References and API declarations differ: libraries that exist only in 32-bit won’t resolve under 64-bit Office, and Declare statements need PtrSafe. That mismatch also presents as this error.

If it still happens

If no entry says MISSING but the error persists, a reference may be present but the wrong version: uncheck and re-add the main suspects. Saving the file after clearing the missing reference makes the fix permanent for the next machine too, as long as that machine doesn’t need the library either.

Common questions

Why does it highlight Date or Left()? Those are built in. When a reference is broken, VBA can’t fully resolve names — and the first built-in name it trips on gets highlighted. The highlight is a symptom, not the culprit.

The file works on my PC but not a colleague’s. Classic missing-reference behaviour: your PC has the library, theirs doesn’t. Clearing the MISSING entry in the file (or installing the component on their PC) fixes it for both.

Related errors

Runtime Error 1004 · Runtime Error 429 · Runtime Error 438