vba 调试由规则触发的 Outlook 2007 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5029141/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:41:19  来源:igfitidea点击:

Debugging an Outlook 2007 script fired by a rule

vbaoutlookoutlook-vbaoutlook-2007

提问by Kev

I'm trying to debug an Outlook 2007 VBA script that's fired by a rule. I've set a breakpoint in the script but it doesn't get hit.

我正在尝试调试由规则触发的 Outlook 2007 VBA 脚本。我在脚本中设置了一个断点,但它没有被命中。

The script is actually a Subin the ThisOutlookSessionobject.

该脚本实际上是一个是SubThisOutlookSession对象。

When I run the rule on a specified folder nothing seems to happen.

当我在指定的文件夹上运行规则时,似乎什么也没发生。

What am I doing wrong?

我究竟做错了什么?

Update:

更新:

I've added a MsgBox "Processing: " & mailItem.Subjectto the script and that pops up just fine when I run the rule. However I can't seem to get the script to stop on breakpoints.

MsgBox "Processing: " & mailItem.Subject在脚本中添加了一个,当我运行规则时它会很好地弹出。但是我似乎无法让脚本在断点处停止。

采纳答案by Nick

I think you may not be doing anything wrong, because I have experienced exactly the same behaviour.

我认为您可能没有做错任何事情,因为我经历过完全相同的行为。

However, in order to debug your VBA, I suggest that you create a macro (via the Tools|Macro|Macros menu) that calls your script function with a test e-mail item that you create in the macro.

但是,为了调试您的 VBA,我建议您创建一个宏(通过工具|宏|宏菜单),它使用您在宏中创建的测试电子邮件项调用您的脚本函数。

Maybe something like this:

也许是这样的:

Sub TestScript()
    Dim testMail As MailItem
    Set testMail = Application.CreateItem(olMailItem)
    testMail.Subject = "Test subject"
    testMail.Body = "Test body"
    Project1.ThisOutlookSession.YourScriptForDebugging testMail
End Sub

This way you can "Step Into" the macro via that Macro dialog again, and do all the debugging you need. It solved my problem, anyway.

通过这种方式,您可以再次通过该宏对话框“进入”宏,并进行所需的所有调试。无论如何,它解决了我的问题。

回答by niton

Any existing item can be used to test code that requires one.

任何现有项目都可用于测试需要一个项目的代码。

Sub passOpenItem()
    'first open an item
    codeRequiringItemParameter ActiveInspector.CurrentItem
End Sub

Sub passSeletion()
    'first select an item
    codeRequiringItemParameter ActiveExplorer.Selection(1)
End Sub

Sub codeRequiringItemParameter(itm As Object)
    Debug.Print "TypeName: " & TypeName(itm)
    Debug.Print "Class...: " & itm.Class
End Sub