VBA Runtime Error 31027—*"Unable to activate object"*—occurs when Excel or your VBA project fails to connect to an external object (like ActiveX controls, databases, or COM components). This isn’t just a minor bug: it can disable macros, freeze your workbook, or block automation entirely. The root cause is usually one of three things: the object is missing, misconfigured, or locked by another process. The fix is always the same: isolate the problematic object, rebuild references, or update dependencies. Below is a precise, actionable guide to resolve it definitively.

What You'll Need

  • Microsoft Excel (2016 or later; VBA is non-existent in older versions)
  • Administrator privileges (for registry edits or COM registry tweaks)
  • Access to the object library or its installer (e.g., Microsoft Access, PowerQuery, or a third-party DLL)
  • A backup of your workbook (just in case)
  • If the error persists: Excel’s VBA editor with error tracing enabled

Step-by-Step Resolution

  1. Restart Excel and your PC Start by eliminating silent failures. Close all open Excel instances, sign out of OneDrive, and restart your computer. If this is a recurring issue, reboot in Safe Mode: hold Shift while clicking the Windows Start button, select "Restart," then choose "Troubleshoot" > "Advanced options" > "Startup Settings" > "Restart" and press F4 to force Safe Mode. Why? Background processes may lock COM objects or corrupt the VBA environment.
  2. Update Microsoft Office The object you’re trying to activate might be outdated. Go to: Start > Settings > Apps > Microsoft 365 > Update now. If this doesn’t work, force-update by running the Office installer from the Microsoft Support page. What to check: Ensure all components (Excel, VBA, COM add-ins) are up to date. Reboot after updates are applied. If that did not work: Reinstall Office from the Microsoft Store with "Keep personal files" selected.
  3. Rebuild VBA Project References The error suggests your project is trying to use an object that isn’t properly linked. Open Excel and press Alt + F11 to launch the VBA editor. Follow these steps:
    1. Close all open modules and windows.
    2. In the Project Explorer, right-click your VBA project (e.g., "ThisWorkbook") > Project References. Delete all entries—do not click "Remove referenced assembly" if it prompts you.
    3. Right-click again and select Add Reference.... Navigate to:
      • For built-in Excel objects: Browse to C:\Program Files\Microsoft Office\root\Office16\REF (adjust version number as needed; check Excel.xlsm’s properties if unsure).
      • For third-party objects (e.g., PowerQuery, ADO, or a DLL): Browse to the installer’s “Libraries” folder or the object’s parent directory (e.g., C:\Program Files\Microsoft Access\Microsoft Access Object Library).
      Key tip: If the object’s path is unknown, search for its file name (e.g., "Microsoft Access Object Library") in File Explorer. Common object names trigger this error:
      • Microsoft Access Object Library
      • Microsoft ActiveX Data Objects x.x Library
      • Microsoft Excel.xl Object Library
      • VBAProject.ko
    4. Click OK. If prompted about checksums, click Retry or OK and let Excel rebuild the project.
    What to check: If you see a yellow warning triangle next to a reference, the file may be corrupted. Delete it and re-add the correct path.
  4. Check COM Registry Settings The Registry can conflict with object activation. Open regedit and navigate to: HKEY_CLASSES_ROOT\CLSID\{GUID} Replace {GUID} with the object’s unique identifier (found in the object’s installer or via a quick search for the reference name). Look for these keys:
    • InprocServer32: Verify the path points to the correct DLL (e.g., C:\Program Files\Microsoft Office\root\Office16\ADODB.DLL).
    • ThreadingModel: Must be set to Both (not Apartment or Free) for most Excel VBA objects. How to find the GUID: In the VBA editor, right-click the reference > Properties. Check the Class field for the GUID.
    If you’re unsure, restore the Registry to a known-good state by creating a backup and copying the entire HKEY_CLASSES_ROOT folder from another machine (with matching Office version) or using System File Checker (sfc /scannow) from Command Prompt.
  5. Repair the Object Library Itself If the object library (e.g., Excel’s VBAProject.ko) is corrupted, reinstall it. For Excel:
    1. Close Excel and all open files.
    2. In Windows Explorer, navigate to: C:\Program Files\Microsoft Office\root\Office16\VBAProject.ko (adjust path for your version).
    3. Delete the file and restart Excel. A new VBAProject.ko will generate automatically.
    For third-party objects, reinstall the application that includes the library (e.g., Access, PowerQuery, or a third-party tool like PowerShell).
  6. Temporarily Disable Add-ins Excel add-ins can conflict with COM objects. Enable debugging in VBA:
    1. In the VBA editor, press F8 to set a breakpoint. If the error occurs at the start, ensure your macro isn’t dependent on add-ins that are missing or misconfigured.
    2. Go to Tools > References > Uncheck all add-ins, then click OK. Test your code again. If it works, enable add-ins one by one to identify the culprit.
    Note: For add-ins like PowerQuery or Access, ensure their setup is complete (e.g., check C:\Program Files\Microsoft Office\root\Office16\PowerQuery exists).
  7. Use VBA Error Tracing Attach the "Immediate Window" to debug the error:
    1. In the VBA editor, press Alt + F8 to open the "Go To Procedure" dialog. Select the macro where the error occurs.
    2. Press F8 to step through the code. When the error happens, check the Immediate Window (Ctrl + G or press Alt + F11 > View > Immediate Window). Look for the error message and the specific line triggering it.
    Example trace: If the error is "Type mismatch," the code is trying to assign a string to a numeric variable. If it’s "Object doesn’t support this property," the object may be missing or misconfigured.
  8. Check for Antivirus Interference Some antivirus software blocks COM objects or Excel’s background processes. Temporarily disable real-time protection from your antivirus (e.g., Windows Defender > Virus & threat protection > Manage settings > Turn off real-time protection). Test the workbook again. Exception: Never disable antivirus completely. Instead, add exceptions for:
    • Excel.exe
    • VBAProject.ko
    • Your workbook’s location

Common Mistakes

  • Adding the wrong reference path: Many users search for the DLL in Windows Update or the Internet and pick the wrong version. Always verify the path matches the Office version (check Excel.xlsm’s properties).
  • Ignoring the ThreadingModel setting: Most Office VBA objects require Both threading. Setting it to Apartment (e.g., for COM objects from other apps) can cause this error.
  • Forgetting to rebuild the project: After adding references, Excel doesn’t automatically update the project. Always close and reopen the VBA editor or press Alt + F11 again.
  • Using a corrupted object library: Deleting VBAProject.ko without reinstalling Office or the object library can leave the system in an inconsistent state.
  • Assuming the error is macro-related: The error can occur when opening a workbook, so check if the issue is tied to a specific file rather than your code.

Tips

  • For Office 365 subscribers: Enable "VBA in Excel" in the Office App (Settings > Options > Trust Center > Trust Center Settings > Macro Settings) to ensure macros are recognized.
  • Use the Object Browser to test if an object exists: In the VBA editor, go to Tools > References, check the box for the object, then press Alt + F11 > View > Object Browser. If the object doesn’t appear, the reference is invalid.
  • For third-party objects: If the object is a DLL, ensure it’s registered with Windows. From Command Prompt, run: regsvr32 path\to\object.dll (e.g., regsvr32 C:\Program Files\OtherObject\MyDLL.dll).
  • Backup your workbook before changes: Rebuilding references or deleting files can corrupt workbooks. Always save a backup before proceeding.
  • Check for Office installations: If you have multiple Office versions (e.g., Office 2016 and 365), ensure you’re adding references to the correct version’s library folder.

Troubleshooting

If none of the above steps work, the issue may be deeper. Try these advanced methods in order:

  1. Repair Excel’s VBA environment Use Excel’s built-in repair tool:
    1. Open Excel, press Alt + F11, then close the VBA editor.
    2. In the VBA editor, press F11 to launch the Immediate Window.
    3. Type the following and press Enter: Dim obj As Object: Set obj = CreateObject("Excel.Application") If this fails, the error persists. Proceed to the next step.
    Alternative: Create a new Excel workbook, paste this VBA code, and run it: Sub TestCOM() On Error Resume Next Dim xlApp As Object: Set xlApp = CreateObject("Excel.Application") If Err.Number <> 0 Then MsgBox "Failed to create Excel object. Error: " & Err.Description Else MsgBox "Successfully activated Excel object." End If Set xlApp = Nothing End Sub If this test fails, the COM infrastructure is broken.
  2. Reset the COM Component Manager This clears cached COM objects:
    1. Open Command Prompt as Administrator.
    2. Run: comexp /reset (Note the space before "/reset").
    3. Reboot your computer.
    Why? Corrupted COM components can cause this error.
  3. Reinstall Office with Repair If COM components are fundamentally broken, reinstall Office:
    1. Go to Control Panel > Programs > Programs and Features.
    2. Select Microsoft Office > Change > Quick Repair.
    3. If that fails, choose Online Repair (may require a valid license).
    If the error persists: Reinstall Office from the Microsoft Store or the official download link.
  4. Check for Office updates via Windows Update Sometimes Office updates are delayed. Go to: Settings > Windows Update > Advanced options > Optional updates > Check for updates.
  5. Restore Windows System Files If the issue started after a Windows update, restore system files:
    1. Open Command Prompt as Administrator.
    2. Run: sfc /scannow and wait for completion.
    3. Restart your PC.
    What this does: Scans and repairs corrupted system files, including COM components.

Frequently Asked Questions

Why does this error only happen in VBA and not in the regular Excel interface?

The VBA runtime relies on COM objects, which are separate from Excel’s UI components. If a COM object is misconfigured, corrupted, or blocked by security settings, only VBA will fail—regular Excel tasks (like opening a file) will continue to work.

What if the object I need is from another company’s software (e.g., a third-party DLL)?

You must manually register the DLL with Windows (use regsvr32 in Command Prompt) or add its reference in VBA via the correct path. If the DLL isn’t registered, CreateObject() will fail. Check the DLL’s documentation for the GUID and threading model requirements.

Is there a way to force Excel to use a specific version of the VBAProject.ko library?

No, but you can create a fresh VBAProject.ko by deleting the old one (found in C:\Program Files\Microsoft Office\root\Office16\VBAProject.ko for Office 2016) and restarting Excel. This ensures a clean, uncorrupted library. For Office 365, it’s generated automatically on first use.

Why does this error happen after a Windows 10/11 update?

Windows updates can break COM compatibility by modifying system libraries or security policies. The error often appears after updates that change registry keys for COM components (e.g., HKEY_CLASSES_ROOT entries). Running sfc /scannow or resetting the COM component manager may resolve it.

Can I use this workaround for Office Online (web-based Excel)?

No, Office Online does not support VBA or COM objects. The error is irrelevant in this context—it only occurs in installed Office versions.

What should I do if I’m using Excel 2010 and this error keeps happening?

Excel 2010 is end-of-life and lacks security updates. The best fix is to upgrade to a supported version (Excel 2013 or later). If you must stay on 2010, avoid third-party COM components and stick to built-in Excel VBA objects.