Fix Word VBA Editor Showing ‘Compile Error: Method or Data Member Not Found’
🔍 WiseChecker

Fix Word VBA Editor Showing ‘Compile Error: Method or Data Member Not Found’

When you press Alt+F11 to open the VBA Editor in Word and run a macro, you may see a pop-up that says Compile Error: Method or Data Member Not Found. This error stops your macro from running and highlights a line of code in yellow. The root cause is usually a missing object reference, a typo in the code, or a broken reference to a library or add-in. This article explains why this error occurs and provides step-by-step fixes to resolve it, including checking references, correcting code syntax, and repairing corrupted projects.

Key Takeaways: Resolving the VBA Compile Error in Word

  • Tools > References in the VBA Editor: Check for broken references marked as MISSING and uncheck them to clear the error.
  • Alt+F11 > Debug > Compile VBAProject: Run this command to identify the exact line with the error and fix typos or missing methods.
  • Export and reimport modules: Remove corrupted VBA modules by exporting them to a .bas file and reimporting into a clean project.

ADVERTISEMENT

Why the VBA Editor Shows ‘Method or Data Member Not Found’

This compile error occurs when the VBA interpreter cannot match a method name or property name to any member of the object you are using. In simpler terms, the code tries to call a function or access a property that does not exist for that object type. For example, if you write ActiveDocument.SaveAs2 but the object does not have a SaveAs2 method, the error appears.

The most common triggers are:

  • Broken references: When a referenced library (like a Word object library or an external COM add-in) is missing or unregistered, the VBA editor cannot resolve the members of those objects.
  • Typographical errors: A misspelled method name, such as Open instead of Open or Close instead of Close, causes the error.
  • Wrong object type: Using a method that belongs to a different object, like calling Paragraphs(1).Bold when Bold is a property of the Font object, not the Paragraph object.
  • Corrupted VBA project: Importing code from an untrusted source or a damaged .dotm file can introduce invalid references that trigger the error.

The error always stops compilation, so the macro will not run until you fix the offending line. The VBA editor highlights the problematic line in yellow and places the cursor near the unrecognized identifier.

Steps to Fix the Compile Error

Follow these steps in order. Start with the simplest check — broken references — and move to code fixes only if needed.

Check and Repair Broken References

  1. Open the VBA Editor
    Press Alt+F11 in Word to open the VBA Editor.
  2. Open the References dialog
    In the VBA Editor menu bar, click Tools and then References. The References dialog box lists all libraries your project uses.
  3. Identify missing references
    Look for any reference that starts with MISSING in the list. For example, MISSING: Microsoft Word 16.0 Object Library indicates a broken reference. Uncheck the box next to any MISSING entry.
  4. Remove orphaned references
    If you see references that point to files that no longer exist on your system (like an old COM add-in), uncheck them. Do not uncheck references that are not marked MISSING unless you are certain they are unused.
  5. Add a fresh reference if needed
    If you removed a Word object library reference, scroll down in the list, check Microsoft Word 16.0 Object Library (or the version matching your Office installation), and click OK.
  6. Recompile the project
    In the VBA Editor, click Debug and then Compile VBAProject. If no errors appear, the fix is complete.

Fix Code Errors by Compiling the Project

  1. Open the VBA Editor
    Press Alt+F11 in Word.
  2. Run the Compile command
    Click Debug in the menu bar and choose Compile VBAProject. The editor will stop at the first error and highlight the line in yellow.
  3. Read the highlighted identifier
    Look at the yellow line. The part that is not recognized will be selected. For example, if the line says Selection.Font.Size = 12 and Font is highlighted, you may have a typo or the object does not have a Font property.
  4. Correct the code
    Fix the typo or replace the method with the correct one. Use the Object Browser (F2) to search for valid methods. For the Font example, ensure you are using Selection.Font, not Selection.Fon.
  5. Recompile after each fix
    Press Ctrl+F5 to recompile. Repeat until no errors appear.

Export and Reimport Modules to Fix Corruption

  1. Open the VBA Editor
    Press Alt+F11 in Word.
  2. Locate the module with the error
    In the Project Explorer (Ctrl+R), find the module that contains the error. It will be under Normal or Project depending on where the macro is stored.
  3. Export the module
    Right-click the module name and choose Export File. Save it as a .bas file to your desktop.
  4. Remove the corrupted module
    Right-click the same module and choose Remove ModuleName. Confirm the removal. Do not save changes to the export when prompted.
  5. Create a new module
    Click Insert in the menu bar and choose Module.
  6. Import the saved file
    Right-click the new module and choose Import File. Select the .bas file you saved earlier.
  7. Compile the project
    Click Debug and then Compile VBAProject. If the error is gone, the corruption was in the module storage. If the error persists, the code itself contains the issue, and you need to fix it manually as described in the previous section.

ADVERTISEMENT

If the Error Persists After Fixing References and Code

Word VBA Compile Error Appears in a Different Document

If the error occurs only in one specific document, the document’s VBA project may be corrupt. Open Word, create a blank document, and try running the same macro from the Normal template. If it works, the issue is in the document itself. Recreate the macro in the new document by copying the corrected code from the .bas file you exported earlier.

VBA Editor Shows ‘Compile Error’ When Opening Word

This usually means the Normal.dotm template has a broken reference or corrupted code. Close Word, rename Normal.dotm to Normal.old, and restart Word. Word creates a fresh Normal.dotm. Then reimport your macros from the .bas file. This clears all template-level corruption without affecting other add-ins.

Error Occurs Only After Installing an Office Update

An Office update might change the version of the Word object library. Open the VBA Editor, go to Tools > References, and verify that Microsoft Word 16.0 Object Library is checked. If the reference points to an older version (like 15.0), uncheck it and check the correct version. Recompile the project.

VBA Editor Compile Error vs Runtime Error: Key Differences

Item Compile Error Runtime Error
When it appears When you compile or run the macro During macro execution
Error message Method or Data Member Not Found Run-time error ‘####’ with specific description
Code highlighted Yes, the line with the error is highlighted in yellow Yes, the line that caused the error is highlighted
Root cause Missing reference, typo, or wrong object member Invalid operation, division by zero, object not set
Fix method Check references, correct code, or export/import modules Add error handling, validate object states, or check data values

Understanding this difference helps you choose the correct fix. A compile error always requires a code or reference change. A runtime error may be fixed by adding error handling or checking object states before using them.

You can now resolve the ‘Method or Data Member Not Found’ compile error by checking references, correcting typos, and recompiling your project. Next, run the macro again to confirm it works. For future prevention, always compile your VBA project with Debug > Compile VBAProject after making changes. A useful advanced tip is to enable Tools > Options > Editor > Auto Syntax Check so Word flags errors as you type, reducing the chance of compile errors.

ADVERTISEMENT