【发布时间】:2015-07-27 07:41:25
【问题描述】:
我在 Win XP 上运行 Outlook 2003。我的 Desktop Alert 已开启且运行顺畅。
但最近我创建了一个 VBA 宏,它将传入的电子邮件分类到几个不同的文件夹中(通过 ThisOutlookSession 中的 item_add 事件)。这以某种方式阻止了桌面警报的显示。
有没有办法从 VBA 代码手动调用桌面警报?也许是某种功能。
P.S:我无法通过规则对我的电子邮件进行排序,这不是一个选项
基本上,我正在使用 RegEx 查找电子邮件中的 6 位代码
我的代码(抱歉,这是我在 Internet 上找到的其他代码片段拼凑而成的
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
非常感谢
【问题讨论】:
-
你能添加你的代码来分类你的邮件吗?集成修改会更容易!
-
好的,我只是稍微修改一下,所以它不包含私人信息。
-
谢谢,因为我看到了一些关于警报的东西,但我将它整合到某些东西中比解释整个事情要容易得多! ;)
-
您有没有尝试过任何解决方案?也许是 Powershell?