Share via

Run-time error '1004': Application-defined or object-defined error

Chris Metrics 0 Reputation points
2026-06-07T06:13:56.4833333+00:00

Open Excel and it said: Run-time error '1004': Application-defined or object-defined error

Please help solve this.

Microsoft 365 and Office | Excel | For business | Windows

3 answers

Sort by: Most helpful
  1. Vivian-HT 17,105 Reputation points Microsoft External Staff Moderator
    2026-06-07T06:44:56.74+00:00

    Dear @Chris Metrics

    From what you described, the ‘1004: Application-defined or Object-defined error’ usually happens when Excel can’t find or use something your macro is referencing - like a sheet, a range of cells, or a named object. In other words, your code is trying to tell Excel to do something, but Excel doesn’t know exactly what you mean.

    To help me narrow down the issue, could you please help me confirm these questions?

    • When you try to open Excel, does the error appear immediately before you can do anything, or only after opening a specific file?​‌
    • If possible, please provide a screenshot of full error message to help me diagnose the issue more effectively. 

    To begin, please try opening Excel in Safe Mode. You can do this by pressing Windows + R, typing excel /safe, and pressing Enter. ​‌

    If Safe Mode works, the next step is to disable all add-ins. Open Excel normally, if possible, go to File > Options > Add-ins, then at the bottom select COM Add-ins and click Go > Uncheck all add-ins, restart Excel, and check if the issue is resolved. You can then re-enable them one at a time to identify the specific add-in causing the problem.​‌

    If the issue still persists, it may indicate a corrupted Office installation. In that case, you can try repair Office apps. When you're done, you might need to restart your computer. For reference, please follow this article: Repair an Office application

    Moreover, here are some common causes and ways to fix it:

    • Make sure the sheet you’re referencing actually exists and the cell or range is correct. Even a small typo can cause this error.
    • When using Range or Cells, make sure to specify which worksheet it belongs to. For example:
       With Worksheets("Sheet1")
           .Range("A1:A10").Select
       End With
    
    • If the sheet is protected, Excel won’t let the macro make changes. You may need to unprotect it first:
       Worksheets("Sheet1").Unprotect "yourpassword"
    

    - Ensure you’re not trying to access a cell or column that doesn’t exist (Excel’s last column is XFD).

    A good approach is to enable debugging in VBA so you can see exactly which line is causing the error. Once you know that, it’s usually a simple matter of correcting the sheet, range, or object reference. For reference: Debugging in Excel VBA

    For more information and troubleshooting steps, you can refer to this article: Excel Application-Defined or Object-Defined Error in VBA

    Disclaimer: These links are shared by community members for your convenience. These point to third-party sites that are not managed or verified by Microsoft. We can’t guarantee the quality, safety, or suitability of any content or software found there. Please review carefully and make sure you understand any potential risks before using

    Note: Please understand that as a forum moderator, my role is to provide general guidance and troubleshooting support. I don’t have access to internal systems or backend tools, and I appreciate your understanding of these limits.

    I hope the information shared helps point you in the right direction. Please try the steps above and let me know if they work. If not, we can continue working together to narrow this down.

    The first response may not always resolve the issue right away, but with your help and more details, we can work toward a solution.

    Thank you for your patience and understanding. I'm looking forward for your reply.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".   

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


  2. Senthil kumar 685 Reputation points
    2026-06-07T06:34:51.92+00:00

    Hi @Chris Metrics

    Thanks for reaching out here.

    Root cause may be in your macro having any issue or broken any add-in or any vba code having issue. please check the above root cause. or please share the screenshot of error message we will try to solve this issue.

    thanks.

    Was this answer helpful?

    0 comments No comments

  3. AI answer

    2026-06-07T06:14:13.7433333+00:00

    The error “Run-time error '1004': Application-defined or object-defined error” in Excel VBA indicates that Excel or another object has raised an error that is not one of the built‑in VBA errors, or that Excel has hit a specific internal limit.

    Common causes and targeted fixes from the provided information:

    1. Custom or host‑defined errors
      • The message appears when code uses Err.Raise or the Error statement with an error number that is not a built‑in VBA error, or when an object (such as Excel) raises its own error.
      • Action:
        • Check the Err object in the error handler (for example, Err.Number, Err.Description, Err.Source) to see which object or application is raising the error.
        • If the code explicitly calls Err.Raise n or Error n with a custom number, ensure it also supplies a clear description, source, and help info so the error can be understood and handled.
        • If the error is being re‑raised after being trapped, make sure Err.Clear has not been called before re‑raising unless all arguments to Err.Raise are supplied again.
    2. Automation/Excel object model issues (when controlling Excel from VBA or another host)
      • When automating Excel, calling Excel objects, methods, or properties without qualifying them with the correct object variable can cause automation errors, including error 1004, especially when the code is run multiple times.
      • Action:
        • Ensure every call to an Excel object, method, or property is fully qualified with the appropriate object variable (for example, xlApp.Workbooks(1).Worksheets(1).Range("A1") instead of relying on implicit references).
        • Review any lines where an unqualified Excel object might appear in the middle of a longer statement and qualify those as well.
    3. Hitting Excel limits (manual page breaks example)
      • Excel has a limit of 1026 manual horizontal page breaks (1023 in Excel 2007). A macro that tries to add more than this limit can trigger error 1004.
      • Action:
        • If the code adds page breaks (for example, via HPageBreaks.Add), ensure it does not exceed the documented limit.
        • Adjust the macro to stop adding page breaks before reaching 1026, or redesign the layout to require fewer manual page breaks.
    4. General automation error handling
      • When accessing object properties or methods that may fail, use structured error handling to identify the exact source.
      • Action:
        • Place On Error Resume Next immediately before the line that accesses the object, then check Err.Number and Err.Source immediately after to see which call failed.
        • Use this information to adjust the code (for example, checking that objects are valid and that the requested operation is supported).

    If the error appears simply when opening Excel without running custom code, it is likely being triggered by an add‑in, startup macro, or automation code that runs at startup. In that case, disable or inspect startup add‑ins and any Workbook_Open or Auto_Open macros to locate and correct the problematic code using the steps above.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.