Written by Allen Wyatt (last updated March 30, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
Devarajan ran into a situation where a workbook became corrupted, but he wanted to recover the macro module that was associated with the workbook. (The macros represented quite a bit of development time.) Devarajan wondered how the module could be recovered.
The answer depends, in large part, on how corrupted the workbook really is and where the corruption is located within the workbook. Much has been written about how to recover corrupted workbooks; the following resources will be of interest in this regard:
http://support.microsoft.com/?kbid=820741 http://www.jkp-ads.com/Articles/CorruptFiles.asp
These pages refer specifically to recovering data, not to recovering the macros in a module associated with a workbook. One thing that you might try in order to get your macros is the following:
Another way to attempt recovery is to use OpenOffice, a free alternative to Microsoft Office. The spreadsheet program in OpenOffice will open Excel files, and it isn't as sensitive to some corruption issues.
If this still doesn't work, try using a low-level file manipulation tool that allow you to read files sector by sector from a disk, and then allow you to see the information in each sector. With most types of files this won't be very helpful. In fact, it wouldn't help you recover any data from an Excel workbook. Recovering macros is a different story, however. They are stored in the workbook in plain ASCII text, so you should be able to recognize the macro code and then copy it from the disk tool.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12712) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Recovering Macros from Corrupted Workbooks.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
If you need to limit the cells that are accessible by the user of a worksheet, VBA can come to the rescue. This doesn't ...
Discover MoreIf you have a macro that selects different columns in a worksheet while processing information, you may get some ...
Discover MoreWith a little bit of work, Excel allows you to format individual characters of the text you place in a cell. If you want ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-03-29 07:27:27
Jose Santos
THANK YOU!
You sir, saved my posterior.
2020-06-22 11:24:27
James McNemar
When I opened my xlsm this morning, it appeared OK, no error messages... But when I went to add more code - poof, it was all gone. Every module was empty. I tried exporting, it wouldn't even save an empty file. When I tried to view code on a form, received message that object not found. Then when I tried to close the file to try reopening, received "catastrophic error" message. File wouldn't close, sheets wouldn't "copy". Had to kill Excel task. Reopening file resulted in same outcome. So I found this post and, much to my surprise, the steps worked. When I opened the file with the Macros disabled, the code was all there again. Thank you! Don't understand the why or the how, but just happy that I was able to recover everything. Thank you again.
2020-02-11 05:19:18
David Patras
I just encountered similar issue. Steps above didn't help me. What helped was to open the excel file in older and clean Office version (o365, ver. 1906) and save it again - thus removing anything that was corrupt in the file.
2019-08-01 02:44:49
Sam Benson
Hi
I've had a couple of issues with corrupted Excel macro files over the last 6 months and have found the following works (though for non-technical it is a bit involved)
1. Install python 3 and get a copy of the oletools package
2. Make a copy of the corrupted file and put in an empty directory
3. olevba -c <name of file.xlsm> > <file to save code into.txt
4. Rename the corrupted xlsm file to zip file.
5. Within the zip file under xl directory delete the vbaProject.bin file
6. Save the zip file and rename back to xlsm (effectively have deleted all excel modules and classes)
7. Open up the renamed file in Excel
8. Import the text file from 3 above into Excel and edit as required.
It is not perfect but has saved me having to re-write/ rebuild / re-record macros from scratch.
Could probably use olevba to backup all the Excel macro code and save problems when codes does fail.
2019-03-31 03:11:36
Petros
Use the MACRO MOVER addin to recover an entire VBA project even from a corrupted workbook that won't open or load (given that its VBA project is intact). Locked VBA projects can be recovered as well. VBA projects can be exported intact, along with code, forms, references, protection settings and compilation directives.
Click 'Export Macros' and select the corrupted workbook, then import the exported [vbaProject.bin] to a 'healthy' macro-enabled workbook.
https://www.spreadsheet1.com/move-excel-vba-projects-from-one-workbook-to-another.html
"...Recovering macros is a different story, however. They are stored in the workbook in plain ASCII text, so you should be able to recognize the macro code and then copy it from the disk tool"
=> No, VBA is stored in a compressed format called RLE, which is not fully readable by text or Hex editors.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments