TL;DR — Tools > References in the VBA editor is your project's dependency list. Each ticked line lets your code use the names from one library:
Word.Application,Dictionary,ppLayoutBlank. The list is saved inside the workbook but resolved again on every PC that opens it. When a library is not on that PC, or is an older version, the line shows MISSING:, and then the whole project fails to compile, usually on an innocent line such asLeftorDatewith Can't find project or library. Fix it by unticking or replacing the MISSING line on that PC. Prevent it by using references only while you develop, for IntelliSense, and shipping the file late-bound, withCreateObjectand no extra references at all.
' With a reference to "Microsoft Word 16.0 Object Library"
Dim wd As Word.Application ' early bound: IntelliSense, named constants
Set wd = New Word.Application
' Without any reference
Dim wd2 As Object ' late bound: works on any PC with Word
Set wd2 = CreateObject("Word.Application")
This is the third article in a cluster on driving other Office apps from Excel. The
PowerPoint and Word guides show the other programs' object models.
This one covers the link between them: how VBA learns what Word.Range or ppLayoutBlank means, and what
happens when that link is broken on someone else's machine. The rule of the cluster still applies:
every object belongs to one application, so say which one.
What you'll learn
- The mental model: references are a dependency list, resolved on each PC
- The four default references and how to add another
- The two compile errors, one for a missing tick and one for a MISSING library
- Why a broken reference makes
Left,DateandFormatfail - How priority order decides which library's
Rangeyou get - How to list references in code, and why not to repair them that way
- Develop early-bound, ship late-bound, with conditional compilation
The mental model: a dependency list that travels with the file
Every name in your code has to be found somewhere. MsgBox comes from the VBA library, Worksheets from
Excel's, and Word.Document from Word's, but only if your project lists Word's library as a reference. Open
the VBA editor (Alt+F11) and choose Tools > References to see the list.
Each ticked line records which library: an identifier and a version number, plus the file it was found in on your PC. The workbook stores the list. It does not store the libraries. So every time the file is opened, VBA looks for each library again on that PC:
| On the other PC | What VBA does |
|---|---|
| same library, same or newer Office version | finds it; Office libraries even upgrade to the newer version |
| the program is not installed | marks the line MISSING: |
| an older Office version than yours | marks the line MISSING:; references upgrade forward, never back |
| a 32-bit-only control on 64-bit Office | marks the line MISSING: |
That table is the whole topic. A reference is a promise that a library will be there, and the promise is checked on a machine you have never seen.
The four defaults, and adding a reference
A new Excel workbook already has four references, and you rarely need to think about them:
- Visual Basic For Applications: the language itself,
Left,Date,MsgBox - Microsoft Excel 16.0 Object Library:
Workbook,Range,Worksheet - OLE Automation: basic COM support
- Microsoft Office 16.0 Object Library: shared Office objects, such as
FileDialog
Inserting a UserForm adds Microsoft Forms 2.0 Object Library. The first two cannot be removed or moved.
To add one, tick it in the list, for example Microsoft Word 16.0 Object Library or Microsoft Scripting Runtime, and click OK. If it is not listed, Browse... lets you point at the library file. The menu is greyed out while a macro is running or paused, so press Reset first.
What you get: IntelliSense on the new objects, their named constants such as wdReplaceAll, New instead of
CreateObject, and type checking at compile time. The CreateObject guide compares
that with late binding in detail; this article is about what the reference costs once the file leaves your
desk.
Two compile errors, two different problems
Most reference trouble arrives as one of two compile errors, and they mean opposite things.
User-defined type not defined. You wrote Dim doc As Word.Document, or Dim d As Dictionary, and the
reference is not ticked in this project. The compiler has never heard of the type. Tick the library, or
switch the variable to Object and create it with CreateObject.
Can't find project or library. The reference is in the list, but on this PC it says MISSING:. The file was built where the library existed and opened where it does not. This is the one that reaches users, because everything worked on the author's machine.
Why Left and Date fail when Word is missing
The confusing part of Can't find project or library is where it points. A workbook with a MISSING Word reference stops on a line like this:
customer = Left(Range("A2").Value, 10) ' highlighted: Left
Left has nothing to do with Word. But when VBA compiles, it looks up each unqualified name through the
references in order, and a MISSING library breaks that lookup. The compiler gives up on the first name it
cannot place, often a common built-in function such as Left, Mid, Date, Format or Trim. The
highlighted function is a bystander.
The fix is on the PC that shows the error:
- Open the VBA editor, press Reset if a macro is paused, and choose Tools > References.
- Find the line that starts with MISSING:.
- Untick it if the code does not need it, or tick the version that this PC has.
- Choose Debug > Compile VBAProject to confirm the project compiles again.
You will sometimes see the advice to write VBA.Left instead of Left. A fully qualified name skips the
lookup, so the line compiles. It hides the symptom; the MISSING reference is still there, and the code that
actually uses that library will still fail.
Priority: which library's Range do you get?
When two libraries define the same name, the list order decides. Excel's library sits above Word's, so in
Excel code an unqualified Range, Shape, Font or Selection means Excel's version. That is why
Dim r As Range followed by Set r = doc.Content fails with a type mismatch, as the
Word guide shows.
The Priority arrows in the References dialog can move a library up, but moving a library to change what a
bare name means is a trap: the next person to add a reference changes it again. Qualify instead:
Word.Range, Excel.Range, Scripting.Dictionary. A qualified name means the same thing whatever the
order.
Listing references in code, and why not to repair them that way
You can inspect the list from VBA through VBProject.References:
Sub ListReferences()
Dim ref As Object, desc As String
For Each ref In ThisWorkbook.VBProject.References
desc = "(unavailable)"
On Error Resume Next
desc = ref.Description ' can fail on a broken reference
On Error GoTo 0
Debug.Print IIf(ref.IsBroken, "MISSING ", "ok "); ref.GUID; " "; desc
Next ref
End Sub
This needs Trust access to the VBA project object model in the Trust Center; without it the first line fails with error 1004, Programmatic access to Visual Basic Project is not trusted. The output goes to the Immediate window, as in the Debug.Print guide.
The same object has AddFromGuid, AddFromFile and Remove, and it is tempting to write a
Workbook_Open that repairs references. Do not rely on it. The setting it needs is off by default and often
locked by IT, and code in a project with a MISSING reference may not even compile far enough to run the
repair. Use code like this for diagnosis on your own PC, not as a fix you ship.
The judgment call: develop with references, ship without them
A reference is a dependency, and every dependency is a promise about the user's PC. My rule: a file that
leaves your machine should carry only the four default references. Everything else goes through
CreateObject and Object variables, which work on any PC that has the program and fail with a clear
run-time error on any PC that does not.
You do not have to give up IntelliSense while writing the code. Conditional compilation lets one switch flip the module between the two styles:
#Const EARLY_WORD = False ' True while developing, with the reference ticked
Sub MakeReport()
#If EARLY_WORD Then
Dim wd As Word.Application
Set wd = New Word.Application
#Else
Dim wd As Object
Set wd = CreateObject("Word.Application")
#End If
wd.Visible = True
' ... the rest of the code is identical ...
End Sub
Develop with EARLY_WORD = True and the Word reference ticked. Before you ship, set it to False and untick
the reference; the lines inside the inactive branch are not compiled, so they need no library. Replace any
named constants with your own Const declarations, such as Const wdExportFormatPDF As Long = 17, which the
Const guide covers. The file then opens on any version of Office, with no MISSING line
to find.
How ExcelMaster helps
Reference problems surface on someone else's PC, as an error on a line that is not wrong. By the time they
reach you, the only description is a screenshot that says Left cannot be found.
ExcelMaster reads the workbook's reference list, finds the MISSING library behind the error, and can rewrite the code to late binding with local constants, so the file stops depending on what is installed on each user's PC.
Frequently asked questions
How do I add a reference in Excel VBA?
Open the VBA editor with Alt+F11, choose Tools > References, tick the library, for example Microsoft Word 16.0 Object Library, and click OK. If the menu is greyed out, a macro is running or paused; press Reset first.
What does Can't find project or library mean?
One of the project's references is marked MISSING on this PC, because the library is not installed or is an older version. Open Tools > References, untick or replace the MISSING line, and compile again. The line the error highlights is usually not the cause.
Why does Left or Date cause a compile error in VBA?
A broken reference stops VBA from resolving names, and common functions such as Left, Mid, Date and
Format are the first to fail. Fix the MISSING reference rather than the highlighted line.
What is the difference between a reference and CreateObject?
A reference gives the compiler the library's types, constants and IntelliSense, but it must exist on every PC
that opens the file. CreateObject finds the program at run time with no reference at all, which is more
portable but gives up IntelliSense and named constants.
Which references does a new Excel workbook have?
Four: Visual Basic For Applications, Microsoft Excel 16.0 Object Library, OLE Automation, and Microsoft Office 16.0 Object Library. A workbook with a UserForm also has Microsoft Forms 2.0 Object Library.
Tested in
Tested in: Excel 365 (Windows 11), VBA 7.1 — last verified 2026-10-02.
Related guides: VBA PowerPoint · VBA Word · VBA CreateObject · VBA Outlook · VBA Dictionary · VBA Const · VBA Option Explicit · VBA Debug.Print
