如何从VBA代码调用Outlook的桌面警报

Zik*_*ato 6 outlook vba outlook-vba

我在Win XP上运行Outlook 2003.我的桌面警报已打开并且运行顺畅.

但最近我创建了一个VBA宏,将传入的电子邮件分类到几个不同的文件夹中(通过ThisOutlookSession中的item_add事件).这以某种方式阻止桌面警报显示.

有没有办法手动从VBA代码调用桌面警报?也许某种功能.

PS:我无法通过规则对电子邮件进行排序,这不是一种选择

基本上我正在用RegEx查看电子邮件中的6位数代码

我的代码(对不起,这是我在互联网上找到的其他代码片段的拼凑

Option Explicit

Private WithEvents olInboxItems As Items

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

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next

Dim targetFolder As Outlook.MAPIFolder
Dim myName As String

Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match

Set Reg1 = New RegExp
myName = "[MyName]"

' \s* = invisible spaces
' \d* = match digits
' \w* = match alphanumeric

With Reg1
    .Pattern = "\d{6}"
    .Global = True
End With

If (InStr(Item.To, myName) Or InStr(Item.CC, myName)) Then    ' if mail is sent or cced to me
    If Reg1.test(Item.Subject) Then
        Set M1 = Reg1.Execute(Item.Subject)
        For Each M In M1
            ' M.SubMatches(1) is the (\w*) in the pattern
            ' use M.SubMatches(2) for the second one if you have two (\w*)
            Set targetFolder = GetFolder([folderPath])  ' function that returns targetFolder
            Exit For
        Next
    End If
    If Not targetFolder Is Nothing Then
        Item.Save
        Item.Move targetFolder
    End If
End If   
End Sub
Run Code Online (Sandbox Code Playgroud)

非常感谢

Eug*_*iev 1

Outlook 对象模型不提供任何用于管理通知的内容。相反,您可以考虑开发一个外接程序,在其中可以使用允许模仿内置行为的第三方组件。例如,看一下RadDesktopAlert组件。

有关详细信息,请参阅演练:创建第一个 Outlook 应用程序级加载项。