gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:56:42 27 4
gpt4 key购买 nike

我在 Win XP 上运行 Outlook 2003。我的桌面警报已打开并运行平稳。

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

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

P.S:我无法通过规则对我的电子邮件进行排序,这不是一个选项

基本上我在用 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

非常感谢

最佳答案

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

Walkthrough: Creating Your First Application-Level Add-in for Outlook了解更多信息。

关于vba - 如何从 VBA 代码调用 Outlook 的桌面警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30258525/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com