The VBA Runtime Error 47—"Too many code resources or DLL applications clients"—occurs when your Excel workbook or VBA project exceeds memory limits due to excessive references to external libraries, fragmented code files, or mismatched DLL dependencies. **Yes, you can fix it by restructuring your macro references, cleaning DLL links, and optimizing your project structure.** This guide shows you how, with no guesswork, to avoid the error without breaking your workflow.
What You'll Need
- A working copy of Excel (2010 or later, with VBA support enabled).
- Your VBA project or workbook file causing the error.
- A temporary folder to back up or test DLL references (Windows only).
- Excel’s VBA Editor (Alt+F11).
- (Optional) A text editor (Notepad++, Visual Studio Code) to inspect/modify `.bas` files if manually restructuring references.
Step-by-Step Solution
-
Check for Too Many References:
Open the VBA Editor (Alt+F11). Go to Project Explorer (left pane) and expand your workbook’s name. Look for the References tab in the top ribbon. If it’s full or contains hundreds of entries, the error is triggered by too many DLLs/libraries. Close the References dialog and count entries:
- Click each box to deselect them one by one. Stop when the list drops to under 50 entries.
- If references remain, enable only critical ones (e.g., Microsoft Excel Objects, VB Project); disable the rest.
-
Merge Fragmented Code into a Single Module:
If your project has multiple `.bas` files (e.g., `Module1`, `Module2`) referencing each other, restructure them into one module:
- Create a new module (Insert > Module) and paste all code from existing modules.
- Delete the old modules and rename the new one (Tools > Options > Editor Options > General > Module Name).
- Update any direct calls in other modules to reference the consolidated module instead.
-
Remove Unused DLLs via VBA Editor:
If the error persists, manually remove DLLs not in use:
- In the References dialog, click the Commercial DLLs group (if present).
- Uncheck every entry except those explicitly needed (e.g., `Microsoft ActiveX Data Objects x.x`).
- For system DLLs (e.g., `Microsoft Scripting Runtime`), check: - Microsoft Visual C++ for Windows Desktop Runtime (optional; enables some functions but is not critical). - Microsoft Internet Controls (if your macros interact with the web).
- Open the VBA Editor and go to Tools > References. Click Remove on any suspicious DLLs.
- Restart Excel and check the References tab again. If the DLL reappears, manually delete it from:
%ProgramFiles%\Microsoft Office\ root\Office16\ (or your Office version)(Replace "16" with your version number; e.g., 19).
- Add a new module named `
` and declare all shared variables/objects here. - Update every module to use these global declarations instead of local ones.
- Delete unused declarations from other modules.
Module1: Dim obj As Object
After:
Global Declarations: Dim obj As Object
- Close all open Excel files.
- Create a new blank workbook (File > New > Blank Workbook).
- Copy-paste only critical code and references from your original workbook.
- Test the new workbook to confirm the error is resolved.
- Search your VBA project for
Private Sub Worksheet_Change()or similar events. - Use the Immediate Window (Alt+F11 > Tools > References > Debug Window) to trace execution flow.
- Remove redundant event handlers or consolidate logic into a single macro.
- Open Event Viewer (Win + X > Event Viewer). Navigate to: Windows Logs > Application
- Filter for Excel-related errors (e.g., "VBA," "ActiveX," "Error 47").
- Note the DLL names causing crashes and remove them from Excel’s References tab.
- Uninstall Excel from Control Panel > Programs.
- Delete these folders:
%ProgramFiles%\Microsoft Office\ root (delete everything except Office16)and%LocalAppData%\Microsoft\Office\ root - Reinstall Office from Microsoft’s official site (do not use third-party installers).
- During installation, select the "Customize" option and uncheck all add-ins.
Common Mistakes
- Overly aggressive reference removal: Removing required DLLs (e.g., `Microsoft Scripting Runtime`) will break macros relying on built-in functions like `SheetFunction`. Always verify dependencies before disabling.
- Ignoring workbook-specific DLLs: Some DLLs are tied to specific workbooks. Detaching them (Step 5) may not work—check the `
- Copy-pasting code without updating references: When merging modules or moving code, ensure all `Dim` declarations and `Reference` entries are updated to match the new location.
- Skipping event handler audits: Circular references between events (e.g., a button click calling a macro that triggers another event) can trigger memory issues. Test code incrementally to isolate problematic loops.
- Not backing up before major changes: Steps like reinstalling Office or deleting DLLs can corrupt your project. Always save a backup workbook before making structural changes (e.g., consolidate modules).
Tips
- Use the "Fix All References" Tool (Microsoft Office 2013+): In the VBA Editor, go to Tools > References and click the Fix All References button. This attempts to consolidate duplicate references, though it may not work perfectly.
- Test in a Sandbox: Create a new workbook, paste only the core logic from your original, and test it. Gradually add back referenced DLLs or modules to identify which ones cause the error.
- Enable Debugging: Set a breakpoint in your macro (click the left margin) and run it (F5). The Immediate Window will show memory errors if they occur. Look for "Out of memory" or "DLL not found" messages.
- Avoid `On Error Resume Next` in Event Handlers: Wrapping event handlers in error-handling code can hide memory issues. Prefer catching specific exceptions (e.g., `On Error GoTo ErrorHandler`) and debug the root cause.
- Use a VBA Helper Tool: Tools like CodeRush (paid) or free alternatives like Refactoring Toolkit can help merge modules and clean up references. Ensure the tool is compatible with your Office version.
Troubleshooting
If the error persists after following the steps, proceed systematically:
- Restart Excel in Safe Mode: Close all Excel instances and run it via:
excel.exe /safeOnly critical macros should work; disable remaining add-ins one by one to isolate the culprit. - Check Office Update Status: Go to Help > Office Update Center and install pending updates. Older Office versions are more prone to DLL conflicts.
- Test on Another PC: If the error occurs only on your machine, it may be tied to system DLL corruption. Test the code on a clean Windows installation or a virtual machine.
- Review Add-In Permissions: Some add-ins (e.g., third-party VBA libraries) may conflict. Disable all add-ins via: File > Options > Add-ins > Manage Office Add-ins and test each one individually.
- Inspect the Workbook File Itself: Open the workbook’s `.xlsm` or `.xlsb` file in a hex editor (like HxD) and search for invalid binary signatures or corrupted sections. If corrupted, repair it via: File > Open > Browse > Click the gear icon > Open and Repair
- Last Resort: Recreate the Workbook: If no other steps work, create a new blank workbook, manually paste critical code from your original file, and test. If the error reappears, the issue lies in the original structure (e.g., cyclic references in event handlers).
Frequently Asked Questions
Why does Excel throw "Error 47" when a macro runs?
Error 47 occurs because VBA has exceeded its memory allocation for managing code resources and external DLLs. This typically happens when you have too many references, fragmented code modules, or circular references between events/macros.
How do I know which DLLs are causing the issue?
Check the VBA References tab in the Project Explorer. Unchecked entries are unused, but if the error persists after removing references, inspect Windows Event Viewer for Excel-related errors (filter for "VBA" or "ActiveX"). DLL names in these logs are likely culprits.
Can I fix this error without disabling all references?
Yes. Focus on reducing the number of references to <50 (per step 1), consolidate code into fewer modules (step 2), and remove only unused DLLs. Avoid disabling critical system DLLs unless you verify they’re not required.
My macros work in Safe Mode but not normally—what’s wrong?
This suggests a third-party add-in or conflicting DLL is interfering. Disable all add-ins one by one (via Add-ins manager) to identify the culprit. If the issue persists, reinstall Office and enable add-ins only after the base system is clean.
Is it safe to delete DLLs from %ProgramFiles%?
Only delete DLLs you’re certain are not required. System DLLs (e.g., `msvcr120.dll`) are critical for Office. Before removing, test if your macros fail with `GetType("Microsoft...")` or other `TypeName` errors.
What if the error occurs only while using certain macros?
Test each macro individually in a new workbook. If the error reproduces, the macro likely has cyclic references or excessive global variables. Audit its logic (e.g., check for `Private Sub Worksheet_Change()` loops) and refactor it into a single module.
Do I need to reinstall Office to fix this?
Only if the error persists after reference cleanup, reinstalling Office is the last resort. This can resolve DLL corruption but won’t work if the issue stems from workbook-specific code structures.
--- This guide covers every plausible root cause and solution for VBA Error 47, with practical steps, precautions, and troubleshooting. The focus remains on direct, actionable fixes without speculation.