Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Recovering Macros from Corrupted Workbooks.

Recovering Macros from Corrupted Workbooks

by Allen Wyatt
(last updated January 16, 2014)

6

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/kb/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:

  1. Open Excel, but not the problem workbook.
  2. Set the calculation mode to manual (Formulas tab | Calculation group | Calculation Options | Manual).
  3. Set the security setting to High (Developer tab | Code group | Macro Security | Macro Settings | Disable All Macros without Notification).
  4. Open the troublesome workbook. If it opens successfully, you should see a notice that the macros were disabled. (If the workbook doesn't open, then you might as well shut Excel down; this series of steps won't work.)
  5. Press Alt+F11 to display the VBA Editor.
  6. In the Project Explorer, locate the module you want to save.
  7. Right-click the module name and choose Export File.
  8. Provide a name and location of where to save the module.
  9. Close the VBA Editor and get out of Excel.
  10. With the module saved in its own file, you can now import it into another workbook, as desired.

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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12712) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Recovering Macros from Corrupted Workbooks.

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

Adding Up Tops and Bottoms

When you are working with sequenced values in a list, you'll often want to take some action based on the top X or bottom Y ...

Discover More

Understanding the VLOOKUP Function

Functions are at the heart of Excel's power in working with data. One of the most misunderstood functions provided by Excel ...

Discover More

Easy Translations

If you work in an international environment, you may have a need to translate text from one language to another. Sheets ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Setting Row Height in a Macro

Macros can be used to change the formatting of your worksheet, if desired. One change you might want to make is to the height ...

Discover More

Running a Macro when a Worksheet is Activated

Want to run a macro when you first select a worksheet? You can do so by using one of the event handlers built into Excel, as ...

Discover More

Pulling Apart Characters in a Long String

You can easily use formulas to pull apart text stored in a cell. For instance, if you need to pull individual characters from ...

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}] 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 7 + 6?

2017-09-21 09:15:54

Alphonse

Hi.
Thank you, thank you, THANK YOU!!!
Your solution works like a charm. Easy peasy.
But you need to include a link to this page of yours, for I believe they go hand-in-hand:
https://excelribbon.tips.net/T012233_Personal_Workbook_Fails_to_Load.html
Thanks again.
Cheers!


2016-11-17 05:30:28

sewe

Save my life :)


2016-04-13 08:12:55

Karin

A more "preventive" option is to have some version control system in place. If anything happens to the workbook or the macro module, you can always roll back to a previous version. One of the few solutions for version control for VBA macro: https://xltools.net/version-control-for-vba-macros/. There are too many things you can't UNDO in Excel, so keep calm and use version control )


2015-06-23 08:17:07

Christian Haase

Hi
one suggestion.
in office 2010:
If you save a workbook with macro having duplicate entry in variables
(sample: Dim x, x as string) you may get a corrupt excel which won#t open correctly.
Use the suggested steps and you remove the error.
thanx


2014-08-07 02:06:11

Ashish

If you want more manual method to diagnose & recover corrupted excel file. To know more how the tool process, click on the below links: http://excelexperts.com/how-open-corrupt-excel-file

It's still worth trying this


2013-11-09 07:42:44

Petros

A lot of Excel users are not aware how to detect minor workbook corruption. They repair damaged files and keep working on them

http://www.spreadsheet1.com/how-to-diagnose-excel-file-corruption-and-repair-workbooks.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."

NOT TRUE = vbproject.bin is not a text file


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.