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
- 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.
- 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.
- 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:
- Close all open modules and windows.
- 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.
- 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; checkExcel.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).
- Microsoft Access Object Library
- Microsoft ActiveX Data Objects x.x Library
- Microsoft Excel.xl Object Library
- VBAProject.ko
- For built-in Excel objects: Browse to
- Click OK. If prompted about checksums, click Retry or OK and let Excel rebuild the project.
- Check COM Registry Settings
The Registry can conflict with object activation. Open
regeditand 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 toBoth(notApartmentorFree) for most Excel VBA objects. How to find the GUID: In the VBA editor, right-click the reference > Properties. Check theClassfield for the GUID.
HKEY_CLASSES_ROOTfolder from another machine (with matching Office version) or using System File Checker (sfc /scannow) from Command Prompt. - Repair the Object Library Itself
If the object library (e.g., Excel’s VBAProject.ko) is corrupted, reinstall it. For Excel:
- Close Excel and all open files.
- In Windows Explorer, navigate to:
C:\Program Files\Microsoft Office\root\Office16\VBAProject.ko(adjust path for your version). - Delete the file and restart Excel. A new VBAProject.ko will generate automatically.
- Temporarily Disable Add-ins
Excel add-ins can conflict with COM objects. Enable debugging in VBA:
- 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.
- Go to
Tools>References> Uncheck all add-ins, then clickOK. Test your code again. If it works, enable add-ins one by one to identify the culprit.
C:\Program Files\Microsoft Office\root\Office16\PowerQueryexists). - Use VBA Error Tracing
Attach the "Immediate Window" to debug the error:
- In the VBA editor, press Alt + F8 to open the "Go To Procedure" dialog. Select the macro where the error occurs.
- 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.
- 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
Boththreading. Setting it toApartment(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.kowithout 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 pressAlt + 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:
- Repair Excel’s VBA environment
Use Excel’s built-in repair tool:
- Open Excel, press Alt + F11, then close the VBA editor.
- In the VBA editor, press F11 to launch the Immediate Window.
- 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.
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 SubIf this test fails, the COM infrastructure is broken. - Reset the COM Component Manager
This clears cached COM objects:
- Open Command Prompt as Administrator.
- Run:
comexp /reset(Note the space before "/reset"). - Reboot your computer.
- Reinstall Office with Repair
If COM components are fundamentally broken, reinstall Office:
- Go to Control Panel > Programs > Programs and Features.
- Select Microsoft Office > Change > Quick Repair.
- If that fails, choose Online Repair (may require a valid license).
- Check for Office updates via Windows Update Sometimes Office updates are delayed. Go to: Settings > Windows Update > Advanced options > Optional updates > Check for updates.
- Restore Windows System Files
If the issue started after a Windows update, restore system files:
- Open Command Prompt as Administrator.
- Run:
sfc /scannowand wait for completion. - Restart your PC.
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.