【问题标题】:VBA Outook 2010 - Coding the ItemAdd EventVBA Outlook 2010 - 编码 ItemAdd 事件
【发布时间】:2017-06-27 23:10:25
【问题描述】:

我在各个网站上看到了许多解决这个问题的帖子,但还没有让它发挥作用。也许我很密集,不知道,但这里有: 事件似乎不想触发。 ThisOutlookSession 内的代码 在子/函数之前的顶部:

'Declare event handler
Public WithEvents myOutlookItems As Outlook.Items 
Private Sub Application_Startup() 
    Set myOutlookItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail).Items 
End Sub 
Public Sub myOutlookItems_ItemAdd(ByVal Item As Object) 
    If TypeName(Item) = MailItem Then 
        MsgBox ("Got a message") 
    End If 
End Sub' 

感谢您的帮助!

【问题讨论】:

  • 看看宏安全性。默认情况下,未签名的宏被禁用
  • 谢谢,但那是非常开放的,我还有其他正在触发的宏(即 application_itemsend )
  • 就像@DmitryStreblechenko 说的使用olMail"MailItem" 应该可以工作。

标签: vba outlook outlook-2010


【解决方案1】:

TypeName 返回一个字符串,所以你的代码应该是

If TypeName(Item) = "MailItem" Then

或者您可以检查 Class 属性的值(所有 OOM 对象都公开它):

If Item.Class = olMail Then ' olMail== 43

【讨论】:

  • 谢谢@DmitryStreblechenko!我已经将其更改为:“If TypeName(Item) = MailItem Then”但我更喜欢您的方法,因此将其更改为“If Item.Class = olMail”
猜你喜欢
  • 1970-01-01
  • 2014-07-11
  • 2022-08-05
  • 1970-01-01
  • 2012-03-18
  • 1970-01-01
  • 1970-01-01
  • 2014-07-31
  • 1970-01-01
相关资源
最近更新 更多