In Excel VBA, “Can’t find project or library” usually means the VBA project has a broken or unavailable reference, not that the workbook itself is missing. Open the Visual Basic Editor, choose Tools > References, restore any missing library or clear its reference if it is not needed, then choose Debug > Compile VBAProject to check the repair.
What the error means
A VBA project can depend on code and features supplied by other libraries. Those references may provide objects, data types, constants, or functions that your own code uses. If Excel cannot locate a referenced library, the compiler may stop with this error—even when the line it highlights appears to use an ordinary VBA or Excel feature.
In the References dialog, a broken entry is commonly shown with “MISSING:” before its name. The workbook may have been created on another computer, or the referenced component may have been removed, moved, or replaced. The project is often still present; it is the dependency that VBA cannot resolve.
The error can appear when you compile, run a macro, or use a workbook function backed by VBA. The exact point where it appears depends on when Excel tries to resolve the unavailable reference. Fixing the reference is usually more useful than editing the highlighted line first.
Why a reference goes missing
References are stored with a VBA project, so a workbook can carry a dependency from the system where it was developed to another system where that dependency is absent or registered differently. Typical causes include:
- A moved or removed library: A project refers to a file or component that was uninstalled, relocated, or is no longer available at its registered location.
- A different Office or Windows setup: A library available on one computer may not be installed on another, or the available version may not match the project’s reference.
- A third-party add-in or application: Code may depend on an add-in, database driver, or other program that is not installed on the current computer.
- A platform difference: A Windows project may use COM or ActiveX components that are unavailable in Excel for Mac.
- A copied or upgraded project: Moving a workbook, changing environments, or updating an application can expose a dependency that was previously satisfied.
A missing reference does not necessarily mean the workbook is corrupt, and the workbook’s filename or folder is rarely the cause. It does mean that some part of the project expects a library VBA cannot currently use. Determine what the project needs before removing the reference, especially if the workbook is shared or business-critical.
How to find the missing reference
Use the desktop version of Excel for Microsoft 365 on Windows for these steps. Open the affected workbook, then press Alt+F11 to open the Visual Basic Editor. On a Mac, Option+F11 opens the editor on many keyboards; depending on your keyboard settings, you may also need Fn. Excel for the web does not run VBA macros.
- In the Visual Basic Editor, select the affected workbook’s project in Project Explorer. If that pane is hidden, choose View > Project Explorer.
- Choose Tools > References. Look through the checked entries for one beginning with “MISSING:”.
- Note the missing library’s name before changing anything. It may point to a particular product or feature the project uses.
- Close the dialog with Cancel if you are not sure what depends on it. If you identify the dependency, restore it or remove its reference as appropriate, then choose Debug > Compile VBAProject.
If the References command is unavailable or the project is locked, you may not have permission to inspect or edit that VBA project. Ask its owner or administrator for an unlocked, corrected copy rather than trying to bypass the protection. Also confirm that you are checking the project that raises the error: a workbook, an add-in, and PERSONAL.XLSB can each have their own VBA project.
Restore the library or remove its reference
There are two main fixes, and the right one depends on whether the project still needs the missing library.
- Restore it when the code depends on it. Install or repair the application or component that provides the library, using an approved installer. Reopen Excel and check Tools > References again. If the library is available but not selected, select the correct entry. Do not download an unfamiliar DLL or register a file from an untrusted source just to clear the warning.
- Clear the reference when it is genuinely unused. In Tools > References, clear the check mark beside the missing entry and click OK. Then choose Debug > Compile VBAProject. If compilation reports an undefined type, function, or constant, the project still relies on that library somewhere; restore it or update the relevant code rather than assuming the reference was unnecessary.
Do not select a similarly named library simply to make the “MISSING:” label disappear. A different version may expose different functions or behavior. If the workbook comes from an employer, customer, or vendor, check with its maintainer before changing references because the missing component may be required for a core workflow.
Early binding, late binding, and code changes
VBA code that declares a variable using a type from another library is early-bound. For example, a declaration using a specific Outlook type requires Excel to resolve the Outlook library at compile time. Early binding offers type checking and editor assistance, but it makes the reference a dependency.
Late binding declares the variable as Object and creates the application object at runtime. This can avoid a compile-time reference to a particular library, but it does not install the required application or guarantee that the object exists. The following small example uses the Windows Scripting Runtime through its COM automation identifier, rather than a checked VBA reference:
Sub CheckDictionary()
' Save a copy of the workbook before running any macro.
Dim items As Object
Set items = CreateObject("Scripting.Dictionary")
items.Add "SKU-1", 12
Debug.Print items("SKU-1")
Set items = Nothing
End Sub
This example is intended for desktop Excel on Windows where the Scripting.Dictionary COM component is available. It prints 12 in the Immediate window; it does not repair a different missing library. Late-bound code loses compile-time checking for the external object’s members, and a missing or unavailable component can still cause a runtime error. Mac support for Windows COM components differs, so do not assume this example will work there. Save a copy before running any macro: VBA actions generally cannot be reversed with Ctrl+Z (or Command+Z on Mac).
Compile the whole project and investigate follow-up errors
After changing a reference, choose Debug > Compile VBAProject in the Visual Basic Editor. Compilation checks the project for additional problems and may reveal errors hidden behind the missing dependency. Follow the compiler’s next message rather than repeatedly changing references at random.
A compile error such as “User-defined type not defined” can indicate that a required library is still missing, particularly when the highlighted declaration names an external type. “Sub or Function not defined” may instead mean a procedure is absent, misspelled, inaccessible, or supplied by an unavailable reference. These messages can have different causes, so inspect the highlighted code and the project’s dependencies together.
If the original error points at a familiar name such as a date or string function, that does not prove the built-in function is faulty. A broken reference can interfere with how VBA resolves names. Fix the missing dependency first, then compile again before rewriting working code.
Excel for Mac, the web, and portability
Excel for Mac includes a Visual Basic Editor and can run VBA, but Windows-only COM and ActiveX libraries are not generally available there. A workbook that depends on Outlook automation, a Windows driver, or another COM component may therefore need a Mac-compatible design, not merely a different reference selection. Check the component vendor’s platform support before assuming there is an equivalent library.
Excel for the web can open many macro-enabled workbooks, but it cannot run or edit VBA macros. To inspect References or compile a VBA project, open the file in desktop Excel. If a workbook must work across Windows, Mac, and the web, identify platform-specific dependencies early and consider whether the required task can be handled with a cross-platform feature, Office Scripts, or a different application design.
Prevent the error in shared workbooks
Before distributing a workbook, review its references on a clean, supported setup and compile the project. Document required add-ins or applications, and tell users which desktop platforms are supported. If a library is optional, avoid making every user install it just to open unrelated macros; isolate the dependent feature and handle its absence clearly.
For long-lived workbooks, keep an unmodified backup and a record of the original reference list before upgrading software or removing dependencies. If a vendor maintains the VBA project, ask for a build that supports your Office version and operating system. This is safer than substituting libraries or deleting declarations without understanding the code.
Frequently Asked Questions
Does “Can’t find project or library” mean my Excel file is missing? Usually not. It generally means VBA cannot locate a library referenced by the project. Check Tools > References for an entry marked “MISSING:” before moving or renaming the workbook.
Can I just uncheck every missing reference? No. Clear a reference only if the project no longer needs it. If code uses its types, constants, or functions, compilation can fail or a feature may stop working. Record the library name and check with the workbook’s maintainer when its purpose is unclear.
Why does VBA highlight a line that looks unrelated? The compiler reports where it first encounters a name it cannot resolve, but the underlying cause can be a missing reference used elsewhere or a name-resolution problem. Repair the reference and compile the full project before editing the highlighted line.
Will changing from 32-bit to 64-bit Excel fix it? Not automatically. Some components or declarations may be architecture-specific, but the error most often points to a missing or unavailable reference. Identify the library first, then confirm that its provider supports your Office architecture.
Can Excel for the web fix VBA references? No. VBA projects cannot be compiled or edited in Excel for the web. Use desktop Excel on a supported platform to inspect references and compile the project.
Related
- Excel Template for Quotation Comparison: Build One
- Excel Task List Template: Set Up and Customize Yours
- Excel Template for a Budget Plan: Build Your Own
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA: Hide a Column RangeTo hide a range of columns with Excel VBA, set its Hidden property to True: use Columns("B:D").Hidden =…
- Documents Folder in Excel VBA: Open It SafelyTo open the current Windows user’s Documents folder from Excel VBA, get its location with the Windows Script…
- Excel Macro VBA Tutorial: Write and Run a First MacroAn Excel macro is a set of instructions that automates actions in a workbook, and VBA (Visual Basic…
- VBA Code to Open an Excel File from SharePointIn Excel for Microsoft 365 on Windows, use VBA’s Workbooks.Open method with the file’s direct SharePoint URL, provided…
- Excel VBA Delete Whole Row: Safe Methods and ExamplesTo delete an entire worksheet row with VBA, use Rows(row_number).Delete, such as Rows(5).Delete for row 5. In a…
- Macro Recorder for Automation: What It Can and Can’t DoYes. Excel for Microsoft 365 on Windows includes a macro recorder that turns many repeated actions into VBA…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.