Excel VBA Compile Error After Microsoft 365 Update: Fix
🔍 WiseChecker

Excel VBA Compile Error After Microsoft 365 Update: Fix

You open a workbook with VBA macros after a Microsoft 365 update and see a compile error message. The error often points to a missing library, a changed object model, or a broken reference. This article explains why Microsoft 365 updates cause VBA compile errors and gives you clear steps to resolve them.

Microsoft 365 updates can change the version of the VBA runtime or deprecate certain objects and methods. When your code depends on a specific library version or uses a now-removed feature, Excel cannot compile the macro. You will learn how to fix library references, update deprecated code, and prevent the error from returning.

Key Takeaways: Fixing VBA Compile Errors After Microsoft 365 Updates

  • Tools > References in the VBA editor: Check and re-link broken library references that cause compile errors.
  • Object Browser (F2) in the VBA editor: Find deprecated or renamed objects and methods to update your code.
  • Manual re-registration of DLL/OCX files via Command Prompt: Restore missing controls like the TreeView or ListView after an update.

ADVERTISEMENT

Why Microsoft 365 Updates Break VBA Macros

Microsoft 365 receives monthly feature and security updates. These updates can change the version number of type libraries such as the Visual Basic for Applications Extensibility library or the Microsoft Office Object Library. When your VBA project has a reference to a specific library version that no longer exists after the update, Excel displays a compile error like “Can’t find project or library” or “User-defined type not defined.”

Another cause is the deprecation of certain objects, methods, or properties. For example, the FileSearch object was removed years ago, but some legacy macros still reference it. Updates can also change the GUID of a library, breaking the reference. Finally, security updates may block or disable ActiveX controls that your VBA code uses, leading to compile errors when the control’s library is missing.

Common Error Messages After an Update

You may see any of these messages:

  • “Compile error: Can’t find project or library”
  • “Compile error: User-defined type not defined”
  • “Compile error: Method or data member not found”
  • “Compile error: Variable not defined”
  • “Compile error: Argument not optional”

All of these point to a missing or mismatched reference.

Steps to Fix VBA Compile Errors After a Microsoft 365 Update

Follow these steps in order. After each step, try to compile your project again by selecting Debug > Compile VBAProject in the VBA editor.

Step 1: Open the VBA Editor and Check References

  1. Open the VBA editor
    Press Alt + F11 in Excel to open the Visual Basic Editor.
  2. Open the References dialog
    In the VBA editor menu, click Tools > References.
  3. Look for broken references
    Any reference marked with “MISSING” is broken. Uncheck that reference.
  4. Re-add the correct reference
    Scroll through the list and check the box for the same library name but with the current version number. For example, if “Microsoft Office 16.0 Object Library” is missing, check “Microsoft Office 16.0 Object Library” if it appears. If the library is not in the list, click Browse and locate the correct .olb or .dll file in C:\Program Files (x86)\Common Files\microsoft shared\OFFICE16 or similar.
  5. Compile the project
    Click OK, then in the VBA editor menu click Debug > Compile VBAProject. If no errors appear, the fix is complete.

Step 2: Update Deprecated Code

If the references are correct but the compile error persists, the code may use a deprecated object or method. Use the Object Browser to search for the problematic identifier.

  1. Open the Object Browser
    In the VBA editor, press F2.
  2. Search for the object or method
    Type the name that appears in the error message into the search box. If the library is missing or the object does not exist, the Object Browser will show no results or a different location.
  3. Replace with the current equivalent
    For example, if your code uses FileSearch, replace it with Application.FileDialog(msoFileDialogFilePicker). If it uses CommandBars, replace it with the Ribbon XML or Application.CommandBars if still supported. Check Microsoft’s VBA reference documentation for the current syntax.
  4. Compile again
    Debug > Compile VBAProject.

Step 3: Re-register Missing ActiveX Controls

If your VBA code uses custom ActiveX controls like the TreeView or ListView, the update may have unregistered the control’s DLL.

  1. Close Excel
    Save all work and exit Excel.
  2. Open Command Prompt as administrator
    Press Windows key, type cmd, right-click Command Prompt, and select Run as administrator.
  3. Re-register the control
    Type regsvr32 "C:\Windows\SysWOW64\mscomctl.ocx" and press Enter. Adjust the path if the control is in System32 or a different folder. Common controls include mscomctl.ocx (TreeView, ListView) and mscomct2.ocx (DatePicker, MonthView).
  4. Restart Excel and test
    Open the workbook and compile the VBA project again.

Step 4: Reset VBA Project References Programmatically

If you manage many workbooks, you can automate the reference fix with a small macro. This macro removes all broken references and re-adds the current version of common libraries.

  1. Insert a new module
    In the VBA editor, click Insert > Module.
  2. Paste the following code
    Sub FixBrokenReferences()
        Dim vbProj As VBIDE.VBProject
        Dim ref As Reference
        Set vbProj = ThisWorkbook.VBProject
        For Each ref In vbProj.References
            If ref.IsBroken Then
                vbProj.References.Remove ref
            End If
        Next ref
        ' Re-add common libraries
        vbProj.References.AddFromFile _
            "C:\Program Files (x86)\Common Files\microsoft shared\OFFICE16\MSO.DLL"
        vbProj.References.AddFromFile _
            "C:\Windows\SysWOW64\stdole2.tlb"
        MsgBox "Broken references removed and standard libraries re-added."
    End Sub
  3. Run the macro
    Press F5 while the cursor is inside the macro. Then compile the project normally.

ADVERTISEMENT

If Excel Still Has Compile Errors After the Main Fix

Compile Error: “User-defined type not defined” on a custom class

This error occurs when a class module references a type from a missing library. Open the class module and check the Dim statements. If the type is from a library like ADODB (ActiveX Data Objects), go to Tools > References and ensure the current version of that library is checked. For ADODB, check “Microsoft ActiveX Data Objects 6.1 Library” (or the latest version).

Compile Error: “Method or data member not found” on a known object

This error means the method or property has been removed or renamed in the new library version. Use the Object Browser to find the correct name. For example, in Excel’s VBA object model, the Range.Phonetics property still exists, but Range.SpecialCells has not changed. Check the Microsoft documentation for the specific object. If the method is truly gone, you must rewrite that part of your code using an alternative approach.

Compile Error: “Can’t find project or library” on every workbook

If this error appears in every workbook you open, the default references in the VBA project template may be broken. In the VBA editor, click Tools > References and note which libraries are checked by default. Uncheck any that show “MISSING.” Then, close and reopen Excel. If the problem persists, run Office Repair from Programs and Features in the Control Panel. Choose Quick Repair first; if that does not fix it, run Online Repair.

Quick Repair vs Online Repair: Key Differences

Item Quick Repair Online Repair
Description Repairs Office files without downloading new installation files Downloads and reinstalls Office from Microsoft servers
Internet required No Yes
Time to complete 5–10 minutes 30–60 minutes depending on connection speed
Fixes missing registry entries Yes Yes
Fixes corrupted DLL files Partial Full
Affects installed add-ins No No

After the first Microsoft 365 update that causes a compile error, you can prevent future issues by setting the VBA project references to use the latest library version and by avoiding deprecated objects. Use early binding with the current type library version, or switch to late binding to avoid version conflicts entirely. Late binding uses CreateObject and Dim variable As Object, which bypasses compile-time reference checks.

You now know how to identify broken references, update deprecated code, and re-register missing controls after a Microsoft 365 update. The next time you see a compile error, start by checking Tools > References for missing libraries. For long-term stability, consider converting your macros to use late binding where possible. This approach reduces dependency on specific library versions and prevents compile errors after future updates.

ADVERTISEMENT