Outlook 在哪里存储 VBA 代码文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/233702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where does Outlook store the VBA code files?
提问by Frep D-Oronge
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
我在 Outlook 中有一个带有一些电子邮件宏的 VBA 项目 - 但是在 PC 崩溃后它们都消失了,当我按下 Alt+F11 时,我看到的只是一个新的“Project1”
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?
我不是 VBA 程序员,但有一组用于电子邮件排序等的方便的宏。我不想再次对它们进行编码。任何人都知道代码文件应该在文件系统上的哪个位置,以便我可以挽救代码?
回答by Dave DuPlantis
This pagehas some really good insight on where Outlook keeps all its stuff. It suggests the following:
此页面对 Outlook 保存所有内容的位置有一些非常好的见解。它提出以下建议:
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.
所有 Outlook 宏都存储在用户的 %appdata%\Microsoft\Outlook 文件夹中名为 VbaProject.otm 的单个文件中,该文件夹在大多数系统上将是一个隐藏文件夹。
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).
展望未来,您可能会考虑定期导出您的宏,以防再次发生这种情况,通过 VBA IDE(右键单击并选择导出文件...)或使用链接文章中提到的工具之一(如Office 配置文件向导))。
回答by Anonymous Type
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.
我假设在问题发生后,您尝试重新登录到相同的 Windows 用户帐户和相同的 Outlook 配置文件。
- Create a new windows login to the machine in question.
- 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...)
- Now Exit Outlook, and make sure it is not running (check for outlook.exe in task manager).
- Open Windows Explorer.
- 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).
- Navigate to C:\Documents and Settings\USERNAME\Application Data\Microsoft\Outlook (or use the environment variable notation %appdata%\Microsoft\Outlook for vista/win7)
- Rename the existing VbaProject.OTM to VbaProject.OTM.OLD
- Paste the VbaProject.OTM from step 5 into this folder.
- Reopen Outlook and test (i.e. Alt + F11).
- Good luck with recovery.
- 创建一个新的 Windows 登录到有问题的机器。
- 登录此帐户并打开 Outlook,这将创建一个新的 Outlook 配置文件。记下配置文件名称(找到这个:控制面板 > 邮件小程序 > 显示配置文件...)
- 现在退出 Outlook,并确保它没有运行(在任务管理器中检查 Outlook.exe)。
- 打开 Windows 资源管理器。
- 复制(不要剪切)现有的 VbaProject.OTM 文件。(如果它有任何其他名称,首先将其重命名为 VbaProject.OTM,然后复制)。
- 导航到 C:\Documents and Settings\USERNAME\Application Data\Microsoft\Outlook(或使用环境变量符号 %appdata%\Microsoft\Outlook for vista/win7)
- 将现有的 VbaProject.OTM 重命名为 VbaProject.OTM.OLD
- 将步骤 5 中的 VbaProject.OTM 粘贴到此文件夹中。
- 重新打开 Outlook 并进行测试(即 Alt + F11)。
- 祝你康复顺利。
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.
如果这不起作用,您还记得添加自签名证书吗?如果是这样,你有证书的副本吗?您可以尝试将其重新安装到证书管理器 (certmgr.msc) 中,将其复制/安装到 Certficiates - Current User\Personal\Certificates 配置单元。
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. "
我刚刚从 Sue Mosher (outlook VBA guru) 中找到了这个注释:“AFAIK,一旦 .otm 文件损坏,就无法恢复。这就是为什么我建议依赖 VBA 代码的人导出他们的模块或备份整个文件。 ”
回答by Heider Sati
All macros are embedded into an OTM file, under the following location:
所有宏都嵌入到 OTM 文件中,位于以下位置:
C:\Users\(***Your User Name***)\AppData\Roaming\Microsoft\Outlook\VbaProject.OTM
To restore, replace this file with the older one, it should work
要恢复,用旧文件替换此文件,它应该可以工作
回答by bp_
Ran into this same problem.
遇到了同样的问题。
- First reviewed the .otm file mentioned by @Anonymous Type and @Dave DuPlantis
- Not corrupted... hmm
- 首先查看@Anonymous Type 和@Dave DuPlantis 提到的.otm 文件
- 没有损坏...嗯
I checked my Ribbon in Outlook for the Developer tab. It was missing and simply re-adding it to my Ribbon fixed my problem.
我在 Outlook 中检查了我的功能区中的“开发人员”选项卡。它丢失了,只需将它重新添加到我的功能区即可解决我的问题。

