Stopping Excel from Deleting Macros from a Workbook

Written by Allen Wyatt (last updated September 17, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


3

Chris has a very large (350 GB) workbook. There are many times, when opening the workbook, that the macros it should contain are stripped out and the workbook is deemed corrupt. In those cases, Chris has to rely on the frequent backups he makes. He wonders how he can stop this from happening.

When I read the question from Chris, my immediate reaction was to question the size of the workbook file. It seems very doubtful that a workbook is actually 350 GB, as limits on both Access and SQL Server files is in the 2 GB neighborhood. This caused me to go look up the limits published by Microsoft:

https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

The page indicates that there are limits similar to Access and SQL Server when running the 32-bit version of Excel. If using the 64-bit version, however, the official word is that you are limited only by "available memory and system resources." So, theoretically, a 350 GB file could be opened.

The germane question, however, is should you open such a workbook, even if you could. Feelings among ExcelTips subscribers are mixed on the answer, with most leaning toward an emphatic "no way!" Most long-time Excel users understand that the larger the workbook file, the more susceptible the file is to problems and corruption.

This tendency would explain Chris' experience with the macros getting stripped off and the workbook showing as being corrupt. It should be noted, as well, that it isn't the macros getting stripped off that corrupts the workbook, but the workbook becoming corrupted that causes the macros to get stripped off—Excel, in the process of trying to recover a workbook it considers corrupt, will routinely strip off the macros.

There is a two-fold solution to this problem. First, open a non-corrupt copy of the workbook and transfer the macro modules to a different, blank, macro-enabled workbook. You can then save the workbook as an add-in, which you can then load back into Excel. In that way, even if your very large workbook becomes corrupted (again), you still have your macros available through your add-in.

The second thing to do is to find ways to make your workbook smaller. This will obviously take some rethinking of how you store your data and what is contained in your workbook. Perhaps, for instance, you could have one workbook for each year of data, for each project, or for each department. How you divvy up the data will obviously depend on the nature of your data, and it will take some work. If you combine this with the previous suggestion to make your macros into an add-in, then your macros will be available in all of your smaller, more manageable, and less corruptible workbooks.

It is worth revisiting my original speculation—is Chris's workbook really 350 GB, or was that a type and the workbook is a much smaller 350 MB? If the smaller workbook is really what Chris is working with, then the same suggestions remain—spin your macros off to an add-in and divide your workbook data into a series of smaller workbooks.

Regardless of the workbook size—350 GB or 350 MB—when dividing up the data into separate workbooks, don't do so by copying the original workbook and trimming it back. If the workbook is corrupted in some way, you'll want to reconstruct the workbook from scratch, copying formulas and values, as necessary, from the problem worksheet. Don't copy entire worksheets, however, to the new workbooks, as that may end up copying the corruption you want to remove.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12983) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Setting the Return Address Used in Word

When you create envelopes with Word, it normally displays a return address by default. If you can't get Word to retain ...

Discover More

Leaving a Cell Value Unchanged If a Condition Is False

Ever want the IF function to only return a value if the condition it is testing is true, and not if the condition is ...

Discover More

Adding Footnotes to Endnotes

Word does footnotes. Word does endnotes. Word doesn't do footnotes within endnotes. Here's a discussion as to why and ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Clean Up Your Macro List

Got a workbook cluttered with all sorts of macros? Delete them and you'll make your workbook easier to manage.

Discover More

Aborting a Macro and Retaining Control

If you need to exit a macro before it is finished running, you can do it using a brute force method, or you can build in ...

Discover More

Using Named Ranges in a Macro

Named ranges are a great capability provided by Excel. You can define all sorts of named ranges in a workbook, but how do ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 5?

2022-09-20 09:58:22

J. Woolley

@Christian S.
If you open your datafile and press Alt+F11 to open VBE, you can edit and test your add-in's VBA as you suggested. Just make sure you press Ctrl+S while the add-in is active in the VBE's window. This will save the changes to your add-in file. If you press Ctrl+S while Excel's window is active, changes to your add-in will not be saved.
You might want to backup your add-in file before making changes, just in case.
See https://sites.google.com/view/MyExcelToolbox/


2022-09-19 04:23:45

Christian S.

I faced similar problems (actually at that time my file was about 700 MB) and I changed it as proposed into one AddIn and one datafile (.xlsx). The advantage: even (maybe twice or three times per year instead of ~once per week) most of the time both files remain usable.
The disadvantage: my macros are living code and need updates and extensions every now and then. Normally I did these updates step by step with my data. Well, changes in the AddIn are lost as soon as you close Excel. You need to remember to save the code e.g. to Notebook before closing and then you can copy the code to the 'master'-file of your AddIn.
Soon you may add personal tabs in the Ribbon. If you are not using the latest version of Excel - which, as I read allow adding a tab on the fly - you may find useful information in https://www.rondebruin.nl/win/s2/win001.htm


2022-09-17 06:00:00

Andrija Vrcan

There is one more solution: Separate the workbook with the data and the workbook with the VBA code, and manage the data via Toolbar or Ribbon.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.