23

I had a VBA project in outlook with a few email macros - but after a PC crash they are all gone and all I see is a fresh 'Project1' when I hit Alt+F11

I'm not a VBA programmer, but had a collection of handy macros for email sorting etc. I would not like to have to code them again. Anyone know where the code files should be on the filesystem so that I might rescue the code?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Frep D-Oronge
  • 2,618
  • 3
  • 27
  • 27
  • 1
    FYI, Please be warned if you are going to delete and reinstall Outlook: Creating a backup of VBAproject.OTM, as it is, doesn't guarantee complete recovery of your VBA script. There's a bug that the file does not reflect recent changes in the script. https://answers.microsoft.com/en-us/office/forum/office_2010-customize/vbaprojectotm-file-size-and-time-stamp-not-updated/0c79604e-f00e-43a0-bd36-cebf4b0ea007 – JY Park Feb 17 '20 at 00:00
  • 1
    @JYPark. Thank you for sharing the link to the bug. As of June 2022, I can confirm the bug still exists. Though it's more about the time stamp being old (not the data within the file being old). It still creates issues if you're backing up that file based on last modified date (an issue I faced). But you should be able to copy that file and completely recover - at least within the same outlook and OS version. – Dr Phil Jun 09 '22 at 21:20

4 Answers4

34

This page has some really good insight on where Outlook keeps all its stuff. It suggests the following:

All Outlook macros are stored in a single file named VbaProject.otm in the user's %appdata%\Microsoft\Outlook folder, which will be a hidden folder on most systems.

Now, the problem is that if you do not see them now, then you probably won't be able to restore them from that location: there is probably either an "empty" project there or no project at all, but if that folder is being backed up, you might be able to restore it.

Moving forward, you might consider exporting your macros periodically in case this happens again, either through the VBA IDE (right-click and select Export File...) or using one of the tools mentioned in the linked article (like the Office Profile Wizard).

Dave DuPlantis
  • 6,378
  • 3
  • 26
  • 30
  • The VBA file is there, and looking inside it with a text editor shows fragments of my macros, but it is also full of nulls and sohs - it is a nasty binary format by the looks of it. It must have been semi corrupted at some point, my code is fossilized in there and I can't get it out. – Frep D-Oronge Oct 24 '08 at 15:29
  • 6
    It is meant to be a binary. I just replaced the file I found with the one from my backup and the code was all visible through the Outlook's Macro Editor. – TomG Sep 18 '13 at 10:24
4

Ok. things to try to fix this...

I assume after the problem occured you tried logging back into the same windows user account, and the same Outlook profile.

  1. Create a new windows login to the machine in question.
  2. Login to this account and open Outlook, this will create a new outlook profile. make note of the profile name (to find this: Control Panel > Mail applet > Show Profiles...)
  3. Now Exit Outlook, and make sure it is not running (check for outlook.exe in task manager).
  4. Open Windows Explorer.
  5. Copy (don't cut) the existing VbaProject.OTM file. (if it has any other name than that, first rename it to VbaProject.OTM, then copy).
  6. Navigate to C:\Documents and Settings\USERNAME\Application Data\Microsoft\Outlook (or use the environment variable notation %appdata%\Microsoft\Outlook for vista/win7)
  7. Rename the existing VbaProject.OTM to VbaProject.OTM.OLD
  8. Paste the VbaProject.OTM from step 5 into this folder.
  9. Reopen Outlook and test (i.e. Alt + F11).
  10. Good luck with recovery.

If this doesn't work do you remember adding self signing certificate at all? If so have you got a copy of the cert? you can try reinstalling it into the certificate manager (certmgr.msc) copy/install it to the Certficiates - Current User\Personal\Certificates hive.

I just found this note from Sue Mosher (outlook VBA guru): "AFAIK, once an .otm file is corrupted, it can't be recovered. That's why I recommend that people who rely on VBA code export their modules or backup the entire file. "

MichaelHuelsen
  • 386
  • 1
  • 4
  • 11
Anonymous Type
  • 3,051
  • 2
  • 27
  • 45
2

All macros are embedded into an OTM file, under the following location:

C:\Users\(***Your User Name***)\AppData\Roaming\Microsoft\Outlook\VbaProject.OTM

To restore, replace this file with the older one, it should work

Shyam Bhimani
  • 1,310
  • 1
  • 22
  • 37
Heider Sati
  • 2,476
  • 26
  • 28
-1

Ran into this same problem.

  • First reviewed the .otm file mentioned by @Anonymous Type and @Dave DuPlantis
  • Not corrupted... hmm

I checked my Ribbon in Outlook for the Developer tab. It was missing and simply re-adding it to my Ribbon fixed my problem.

bp_
  • 402
  • 4
  • 14