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

Understanding Document Variables

When working with macros, you may want to create a variable that will remain constant from one instance of the macro to ...

Discover More

Open Workbooks Don't Display

Have you ever opened a workbook, only to have it not display your worksheet data? This can be very disconcerting, but it ...

Discover More

Contractions Flagged as Incorrect

Word, in its never-ending quest to second-guess and try to improve your writing, may be marking your contractions as ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Deleting Worksheet Code in a Macro

When creating an application in VBA for others to use, you might want a way for your VBA code to modify or delete other ...

Discover More

Macros Not Available in Later Versions of Excel

What would you do if you had a macro-enabled workbook that refused to work properly on computers using later versions of ...

Discover More

Copying Named Ranges

Named ranges are a great tool to use in developing formula-heavy workbooks. You may want, at some point, to copy your ...

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 two more than 7?

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.