After you create a VBA macro in Outlook, how do you back it up, save a copy, or copy it to a new computer?
There are three ways to make a copy of your macros:
Copy the contents of ThisOutlookSession (and any modules) and paste into notepad, saving the macro(s) as a text file.
Right click on ThisOutlookSession and choose Export File. You'll need to do for each module (if any) in your Project.
Close Outlook and locate the VBAProject file. Copy it to make a backup.
In Windows 7, 8, or Vista, paste %appdata%\microsoft\outlook in the address bar of Windows Explorer and press Enter to jump to the C:\Users\username\AppData\Roaming\Microsoft\Outlook folder where VBAProject.OTM is. Copy it to make a backup.
In Windows XP, paste %USERPROFILE%\Application Data\Microsoft\Outlook in the address bar of Windows Explorer and press Enter. This will open Windows Explorer to C:\Documents and Settings\username\Application Data\Microsoft\Outlook. Copy the VBAProject.OTM file.
Which method is better? It really depends on your needs. Copying the VBAProject.OTM file insures you have everything in the project and can drop it in the Outlook folder to restore the macros. Copying the code to a text file may be easier to share with others or to copy some macros to another computer that has Outlook macros already in use.
Outlook crashes on me when I do Developer / Visual Basic, so none of the methods are useable. I suppose the VbaProjet.OTM is the source of the crash.
How can I avoid this and save my code base ?
The OLM is corrupt and unfortunately there is no method to repair it. Close Outlook and rename the OLM file at
C:\Users\%username%\AppData\Roaming\Microsoft\Outlook to create a new one or, restore a backup if you have one.
How extensive are the macros? You won't be able to get more than the module names and little bits of code from the olm file (opened in notepad). When mine was corrupted, it had a bunch of php scripts added to it for some reason. (They were scripts I wrote for another application.)
I now try to remember to drag modules to a folder on my hard drive after editing - I sometimes forget but at least I will have something to work with if it gets corrupted again.
For me the file is not yet corrupt since Outlook reads it and partly executes the macro's
am I wrong ?
Maybe I just don't want to accept reality ...
All of my code is VBA basically, no PHP scripts
I think it is still corrupt. If you cant open the editor, there is no way to make a copy of the macros or edit it and there is no way to repair it.
Is the size of the OLM file on your hard drive about what you'd expect for the number of macros? Obviously hard to know for sure - but mine was around 3MB when it went bad. I had problems with it before and it seemed to happen when the file approached 3MB.
My current olm files is around 600 KB - 26 modules - some have macro just a few lines, other have 2 or 3 macros with 20 or 30 lines.
Close Outlook, make a copy of the olm and open it in notepad. Eyeball it and see if there appears to be any code in it that doesn't belong.
Please disregard/delete last post - after explicitly saving the vbaproject.otm project on the source, the copy worked.
I copied the vbaproject.otm file from one computer to another using the path you described. (for both source and destination). Windows File Explorer confirmed that it replaced what was there, but when I opened Outlook, none of the code changes in the source vbaproject.otm appeared. I know there are known problems with vbaproject.otm (such as time/date stamp never updating), but I have no clue on this one - will be forced to use module export/import.
Hi, I hope it is possible to write a macro that will go through all modules of the project and save each of them in *.bas format in a selected folder. I do not seem I can get such a simple logic in VBA. Could you help?
Outlook's VB object model doesn't support exporting the modules using code. You can drag them to File Explorer (its faster than using File > Save) - but need to do it one at a time.
Based on this write up. We can transport the macro to another outlook instance. But the macro I wrote ends up with a button on the ribbon. Would that still need to be done manually?
I'm looking to push this out to all of our computers. We already know we can do an export/import. We are trying to push this out silently with little to no user involvement.
Looks like the copy OTM method finally dies - getting this new pop-up for the first time ever after all these years:
Office has identified a potential security concern Warning the digital signature has been tampered with.
Are you using signed macros? Was the otm you copied signed with the same digital signature as the one it replaced?
Yes to signed (with SelfCert). But the not the same cert as the destination was / is a new insider build. But this approach has always worked in the past -- I keep a copy of the OTM and move it into the folder on the new build and off we go.
Thank you Diane.
What is the name of the xml file and where will I find it?
it's "Outlook Customizations (olkexplorer).exportedUI" - you can save it anywhere for easy access, default location should be in documents.
I am having a similar problem in Outlook 2010, but in addition to the code I need to back up the icon assigned to the macro on my QAT. Anyone got ideas?
if you export the customizations, the icon you assigned to the button is included in the xml file that holds the customizations.