Microsoft Excel is one of the most popular spreadsheets used across the globe for both individual and business purposes. It is the one-stop destination for storing, organizing, and manipulating data in an organized way. MS Excel comes mainly in two extensions i.e. XLS and XLSX format. However, apart from its incredible popularity, runtime errors are a common nuisance for many Windows users – and one of the most common ones is the Runtime Error 1004.
In this guide, we will discuss this common Runtime error 1004 and some of the best fixes to resolve it effortlessly.
What is Runtime Error 1004 in Excel?
Runtime error 1004 is an error code relating to Microsoft Visual Basic that has been known to disturb Microsoft Excel users. This error is faced by any version of MS Excel, such as Excel 2021, 2019, etc. No version of Microsoft Excel is safe from the menace of Runtime Error 1004. In some cases, you may see the runtime error 1004 in Excel after opening a worksheet. Such types of runtime errors usually occur due to a problematic add-in.
Users mainly encounter this error while they are working on an Excel file or trying to generate a Macro in the Excel document. It can cause serious trouble while working with Visual Basic Applications and can completely crash a program or even the entire system; sometimes it may freeze the system, prohibiting the users from doing anything on their system.
Types of Runtime error 1004 messages:
The error messages that are most associated with this runtime error are as follows:
- Runtime error 1004 Paste method of worksheet class failed
- Programmatic access to Visual Basic Project is not trusted
- Run-time error 1004, Cannot run the Macro in Excel
- VB: run-time error 1004, Application-defined or object-defined error
- Excel VBA Runtime error 1004, Select method of Range class failed
- Runtime error 1004, Method range of object _global failed visual basic
- Runtime error 1004 method open of object workbooks failed
- Run-Time error 1004, Method ‘Ranger’ of Object’ Worksheet’ Failed
- Run-time error 1004, Activate method of Worksheet class failed
If you encounter any of these above errors, then you can fix the error using our guide.
What causes Runtine Error 1004?
Error 1004 is a general code related to MS Excel but is not specific to one exact cause. Hence, in this case, the exact reason why this error might pop up will vary from case to case and circumstance to circumstance. From configuration issues to software problems, below we listed a synopsis of common reasons for runtime error 1004 in Excel:
- MS Excel Desktop Icon might be corrupted
- VBA Excel File is clashing with other application
- Due to application or object-specified error
- Due to missing dependent file
- Due to Virus, Trojan or malware
- Due to Invalid Registry Keys and so on.
These were a few of the most common reasons behind getting the runtime error 1004 in MS Excel; now, let us understand the different fixes.
Fix Runtime Error 1004 in Excel
Here, we have detailed both manual and automatic solutions to fix the Runtime Error 1004. You can follow any one of the next methods to resolve the issue.
- Create a new Excel template
- Launch Excel in Safe Mode
- Run a Virus Scan
- For VB: run-time error ‘1004’, Resize legend entries
- Fix for Run-time error 1004, Cannot run the Macro in Excel.
Let’s look at each of these methods in detail.
1] Create a new Excel template
In some cases, fixing this issue can be as simple as inserting a new worksheet from a template instead of creating a copy of an existing worksheet. Here is what you need to do:
1] Open MS Excel on your system
2] Press ‘CTRL + N’ to create a new Microsoft Excel worksheet or simply select a ‘Blank workbook’ from the first screen.
3] Once done, delete all the sheets on the workbook except one.
4] Now, format the workbook which has been left. Also, note that this workbook can be modified to suit your needs.
5] Finally, go to ‘File > Save As’ to save the new worksheet with the Excel Template (.xltx or .xlt) file format.
6] Once you have successfully created the template, you can insert it programmatically by using the following line of code:
Sheets.Add Type:=path\filename
Please note: Do not forget to replace the new filename with the actual name of the document.
2] Launch Excel in Safe Mode
If Excel is showing you the runtime error 1004 after opening an Excel file, there might be a problematic add-in causing the issue. The affected users received the error message given below:
Run-time error ‘1004’: Activate method of Worksheet class failed
To check if the problem is caused by an add-in or not, launch Excel in Safe Mode. If Excel opens successfully in the Safe Mode, the problem occurs due to an add-in. Now, you have to identify the problematic add-in. To do that, follow the steps provided below:
- In Safe Mode, go to “File > Options > Add-Ins.”
- Select COM Add-ins in the drop-down on the right side and click Go.
- In Safe Mode, some add-ins are disabled. You have to enable the disabled add-ins one by one. Enable one of the disabled add-ins and restart Excel in normal mode. See if the error occurs.
If the error occurs, repeat the above steps again. After you find the problematic add-in, consider removing it from Excel.
Read: Fix Runtime Error 1004 in Excel.
3] Run a Virus Scan
It is very important to scan your computer system for malware and viruses as these can corrupt files and important documents and show the runtime error 1004 in MS Excel. Sometimes, using a good antivirus program helps a lot.
4] For VB: run-time error ‘1004’, Resize legend entries
If you come across a Runtime Error 1004 when running a Microsoft Visual Basic for Applications (VBA) macro, then you can use this method to work-around.
Generally, you get this error when you try to run a VBA macro that uses the LegendEntries method to make changes to legend entries in a Microsoft Excel chart. That time, you may receive the following error message:
Run-time error ‘1004’: Application or object-defined error
This error occurs when the Excel chart contains more legend entries than there is space available to display the legend entries on the Excel chart. When this behavior occurs, Microsoft Excel may truncate the legend entries.
To work around this behavior, create a macro that reduces the font size of the Excel chart legend text before your VBA macro changes the chart legend and then restore the font size of the chart legend so that it is similar to the following macro example.
Sub ResizeLegendEntries() With Worksheets("Sheet1").ChartObjects(1).Activate ' Store the current font size fntSZ = ActiveChart.Legend.Font.Size 'Temporarily change the font size. ActiveChart.Legend.Font.Size = 2 'Place your LegendEntries macro code here to make 'the changes that you want to the chart legend. ' Restore the font size. ActiveChart.Legend.Font.Size = fntSZ End With End Sub
5] Fix for Run-time error 1004, Cannot run the Macro in Excel
The first thing you will be required to do is to open Excel Options, which is easy. Just open Microsoft Excel, then click on File, and from there, select Options.
Once you’re in the Options area, please click on Trusted Center, then Trust Center Settings.
Right away the Trust Options section should appear. From there, please select Macro Settings.
Finally, click on Trust access to the VBA project object model, then hit the OK button and that’s it for that.
We hope this article helps you fix the runtime error 1004 in Microsoft Excel. This guide gives you manual as well as automatic solution to get rid of this error; you can make use of any solution based on your need.
Related: Runtime Error 76: Path not found in Excel
How do I fix a Runtime error?
Runtime errors occur at the time of running a program. The runtime errors usually freeze or crash the affected program or software. To fix a runtime error, you can use general fixes, like installing the latest Microsoft Visual C++ Redistributables, running the SFC and DISM scans, troubleshooting in a Clean Boot state, etc.
Read next: Arrows keys not working in Microsoft Excel.