Can’t Find Project or Library – VBA Compile Error

Written by

Mel Jenkins

Reviewed by

Steve Rynearson

Last updated on February 5, 2022

This article will demonstrate how to fix the VBA Compile Error: Can’t Find Project or Library.

The VBA Compile Error – Can’t Find Project or Library occurs when your VBA code refers to an external project or library that cannot be found on the user’s PC.  To fix this, make sure that the reference exists in the correct location.

Add Reference to VBA Project

If you have referred to an external project or library in your VBA code, you need to reference the project or library.

Let us have a look at the following code example:

Sub CreateWordDocument()
  Dim wdApp As Word.Application
  Dim wdDoc As Word.Document
'open word
  Set wdApp = New Word.Application
'create a document
  Set wdDoc = wdApp.Documents.Add
'type some stuff
  wdApp.Selection.TypeText "Good morning!"
'show word on the screen
  wdApp.Visible = True
End Sub

This code is referring to the Word object.

Set wdApp = New Word.Application

In order for this code to run correctly, a reference to the Word object library needs to be added to the VBA project.

In the Menu, select Tools > References.

vbacompile error reference


Scroll down through the list of references to find the one you want to use.  In this case, the Microsoft Word 16.0 Object Library.

vbacompileerror add reference

(1) Select the reference and then (2) click OK and then Save your File.

Finding a Missing Reference

If your VBA project does contain a reference such as shown above, but the reference file is missing, when you try to compile the VBA code, you will get the compile error – Can’t find project or library.

vbacompile error cant find library

In the Menu, select Tools > References.

vbacompile error missing reference

If a reference is selected, but the file for that reference is missing, then it will show the word “MISSING” in front of the available reference.  The file for the reference has been registered on the machine but the actual file has either been removed from the machine, is corrupt so cannot be used or has been moved from the location registered.

To solve this problem, remove the reference from the VBA Project by deselecting the reference and then clicking on OK.

If you then open the reference box again, the missing reference will be removed and you should be able to compile your VBA code.

vbacompile error references

Of course, if you are using that reference in your code (ie Word. Application), then when you re-compile the VBA Project, you may end up with another error!

vbacompile error cant find library

You will need to find the missing file reference, make sure that it is registered on your computer, and make sure it’s in the correct location as indicated in the Location path at the bottom of the dialog box.


VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples