-1

如何在收到具有指定主题或发件人的消息时显示 MsgBox 或警报?

我把这个程序放在ThisOutlookSession块中。

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
    Dim myMail As MailItem
    Dim name As String

    If TypeOf Item Is MailItem Then
        Set myMail = Item
        If myMail.Subject Like "*Hello world*" And myMail.Categories = "" Then
            MsgBox "Message", vbInformation, "approved"
            MailDate = myMail.ReceivedTime
            myMail.Categories = "CZEART"
            myMail.MarkAsTask (olMarkNoDate)
            myMail.Save
        End If
    End If
End Sub
4

1 回答 1

1

To test the code, open a mailitem with the required conditions then step through this.

Option Explicit

Private Sub test()
    Dim currItem As MailItem
    Set currItem = ActiveInspector.currentItem
    olInboxItems_ItemAdd currItem
End Sub

Likely though you need this in the ThisOutlookSession module.

Option Explicit

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
  ' instantiate objects declared WithEvents
  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
  Set objNS = Nothing
End Sub

http://www.outlookcode.com/article.aspx?id=62

于 2014-08-26T11:27:32.770 回答