Reducing File Size
Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Reducing File Size.
James complained about an oddity that he noted with his workbooks. He has a workbook to which he added some macros, and doing so increased the size of the file used to store the workbook. (This makes sense—the macros are stored with the workbook.) When James later deleted the macros, Excel did not shrink the size of the workbook file back to its original size.
This behavior is viewed by some as poor design in Excel—the macro data is removed, but the file size remains bloated. There are a couple of things you can try to again regain your svelte file size.
First, try using Save As instead of Save. Doing so causes Excel to create a brand new file for your workbook, and in the process, free up some space. If that doesn't work, you should try individually copying your worksheets to a brand new workbook, and then saving the new workbook. If doing that doesn't work, then you can try copying just the worksheet data (not the actual worksheets) to a different workbook. Obviously, this can become quite time-intensive.
Another thing to try, provided you still have some macros in the workbook, is a free utility called CodeCleaner, written by Excel MVP Rob Bovey. You can find the program on this page:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2507) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Reducing File Size.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Leave your own comment:
Comments for this tip:
Mohan 07 Nov 2015, 03:21
my excel file size is 25.4 MB (26,697,811 bytes) i can't open please kindly suggest me how to open my excel file
Petros 31 May 2015, 04:12
The easiest way to remove all VBA code from a macro-enabled Office file is to save the file in a macro-free format. For example, save a .xlsb workbook as .xlsx
However you should not open any workbook that you suspect that it has malicious macros or code with bugs that may damage your data or PC. If you disable macros, then you are left with no choice other than to delete macros manually or open and save each file in a macro-free format.
However, the Macro Mover add-in allows you to mitigate security risks and work more productively:
Macros are removed from closed files only! There is no need to disable all macros from the Trust center. Your files will not be opened in Excel, so VBA code cannot be executed.
Code is deleted from closed files, so you don't have to wait while opening/saving large files.
VBA code can be removed from any macro-enabled Office file (including add-ins), even from locked VBA projects.
Macros can be removed without changing the extension of the file. You can still take advantage of the high compression ratio offered by binary files (.xlsb), while erasing macros fast
Petros 31 May 2015, 04:09
Ribbon Commander offers the CleanVBAProject method, which can remove all code garbage from any macro-enabled or binary workbook and Add-ins instantly.
The Ribbon Commander VBA cleaner removes all redundant caches from closed files, so VBE doesn't get a chance to replace the information.
Cleaned files are smaller in size. Nowadays files are moved between desktops and the cloud more frequently than ever before. On an enterprise level, smaller files translate into decreased costs for online storage and bandwidth. Backups and downloads can be executed faster. Email bouncebacks could be stopped and email storage requirements could be reduced.
For years the 'golden' standard for Excel VBA code cleaning has been module export - import.
Ribbon Commander aims to raise the bar by offering several productivity advantages for VBA developers.
Reclaim existing storage space on desktop PCs and servers by replacing large macro-enabled Microsoft Office files with smaller versions. Slow storage growth as new files are added.
David Ruben 14 Apr 2015, 21:20
Thank you David Baker - previously I would try manually selecting the column beyond my last entry, Shift+Ctrl+Right-arrow to select all rows to right and then right-click delete; and then similarly for rows.
Of course nothing bloats a workbook more that setting it up as a shared workbook that can be opened and edited by different users at the same time. Even if one limits the number of days that the change history is kept for, the file size seems inevitably to expand. The solution I use is somewhat clumsy, but I work out the file size when empty of data (but with headers, formating, any lookup tables for validation rules, macro code etc) and then how it increases with additional rows of data. This allows a macro to then calculate what the approximate size of the file should be for the given number of rows of records it has. A macro then automatically:
a) checks if the actual file size exceeds a preset multiple of the calculated presumed size (e.g. x3)
b) checks if the number of active users is just 1
c) then will offer to unshared the workbook (which causes the file to be saved), and then resaved again as a shared workbook.
This inelegantly but effectively clears the history and the bloating for shared files.
David Baker 05 Apr 2015, 17:35
Thank you for your useful Excel and Word tips - great work.
Excel file bloat is problem that I have seen a number of times over the years even in workbooks without macros. There is an excellent piece of code that I have used successfully over the years, ExcelDiet.
The results have been outstanding in some situations when Excel gets confused about the actual range used by the workbook.