Outlook VBA 脚本不会运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25944716/
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
Outlook VBA script will not run
提问by Jeff
I created a VBA script in Outlook 2010 but the only way it will run is by clicking on the play button while in Outlook VBA as indicated in the image below:
我在 Outlook 2010 中创建了一个 VBA 脚本,但它运行的唯一方法是在 Outlook VBA 中单击播放按钮,如下图所示:
Why won't it run when I select the VBA script from the menu as indicated in the image below? I have already signed the VBA script by using "SelfCert.exe".
为什么当我从下图所示的菜单中选择 VBA 脚本时它不会运行?我已经使用“SelfCert.exe”对 VBA 脚本进行了签名。
The other two VBA scripts in the list do run when they are selected from the menu. Below is the code of the VBA script that does not run:
列表中的其他两个 VBA 脚本在从菜单中选择时会运行。以下是未运行的 VBA 脚本的代码:
Sub ReplaceIPs()
Dim Insp As Inspector
Dim obj As Object
Set Insp = Application.ActiveInspector
Set obj = Insp.CurrentItem
obj.HTMLBody = Replace(obj.HTMLBody, "192.168.1", "255.255.255")
Set obj = Nothing
Set Insp = Nothing
End Sub
The above VBA script is supposed to find and replace all instances of "192.168.1" with "255.255.255" in the body of the email that is being composed.
上面的 VBA 脚本应该在正在编写的电子邮件正文中查找和替换所有“192.168.1”实例为“255.255.255”。
采纳答案by Michael Petch
A Module name can't contain a Macro of the same name. Rename the moduleReplaceIPs
to something else or rename the macro/subroutine ReplaceIPs
with something else. If they are both the same it won't resolve properly
模块名称不能包含同名的宏。将模块重命名为ReplaceIPs
其他名称或将宏/subroutine重命名为ReplaceIPs
其他名称。如果它们相同,则无法正确解析
回答by Amitava 'Ami' Pal
In case it helps anyone, none of the methods in my Outlook VBA module were getting control, because the entire module was failing to pre-compile, because I had an extra "." in front of a "Sub" stmt
如果它对任何人有帮助,我的 Outlook VBA 模块中的任何方法都没有得到控制,因为整个模块都无法预编译,因为我有一个额外的“。” 在“Sub”stmt 前面
Trying to run an arbitrary method ("F8") showed the problem.
尝试运行任意方法(“F8”)显示了问题。