Written by Allen Wyatt (last updated August 31, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 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:
https://support.microsoft.com/en-us/office/7abfc44d-e9bf-4896-8899-bd10ef4d61ab https://support.microsoft.com/en-us/office/153a45f4-6cab-44b1-93ca-801ddcd4ea53 https://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.
Still another approach is to use a tool that will specifically extract macros from a workbook. Doing this can get pretty techie, but if you are so inclined, you may find the discussion and tools at this site of interest:
https://www.decalage.info/vba_tools
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.
Finally, if you spend a lot of time developing macros (as Devarajan apparently does), then you may want to build into your development routine a way to backup your macros. There are many ways you could do this, but a very simple way is to simply export the module(s) in which your macros are stored. That way you'll have them available in plain text format, in a BAS file, that you can access and read with any text editor.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12712) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 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.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
When creating macros, it is helpful to know what is going on within the macro itself in case an error crops up. Here's ...
Discover MoreCreating macros can help extend what you can do in Excel. If you work with macros, you know that creating macros from ...
Discover MoreWhen you open multiple workbooks, the way in which Excel sizes them is not the best for your needs. This tip looks at a ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-08-31 10:06:39
J. Woolley
Also, consider https://www.thevbahelp.com/vbe-extras
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 © 2025 Sharon Parq Associates, Inc.
Comments