【问题标题】:Prompt when new email contains certain text当新电子邮件包含某些文本时提示
【发布时间】:2022-02-06 00:35:15
【问题描述】:

我有一个宏,它可以读取收件箱(Outlook 2016)中新电子邮件的内容并弹出一个带有主题和时间的 msgbox。

如果 msgbox 处于活动状态并且同时有新电子邮件到达,则它不起作用。

有没有什么方法可以立即弹出下一个msgbox来获取最新的邮件?

我尝试通过将宏添加到自定义功能区来手动运行宏,但这不起作用,因为它是私有函数。

Option Compare Text
Private WithEvents myOlItems  As Outlook.Items
        
Private Sub Application_Startup()
    Dim olApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Set olApp = Outlook.Application
    Set objNS = olApp.GetNamespace("MAPI")
    Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
        
Private Sub myOlItems_ItemAdd(ByVal item As Object)
        
    On Error GoTo ErrorHandler
        
    Dim Msg As Outlook.MailItem
        
    If TypeName(item) = "MailItem" Then
        Set Msg = item
            
        If Msg.subject Like "*abc.com*" Then
            MsgBox "This is a priority email" & vbCrLf & vbCrLf & "Subject: " & Msg.subject & vbCrLf & "At: " & Msg.SentOn, vbOKOnly, "Priority Email" 'Msg.Subject & vbCrLf & Msg.Body
        ElseIf Msg.Body Like "*abc.com*" Then
            MsgBox "This is a priority email" & vbCrLf & "Subject: " & Msg.subject & vbCrLf & "At: " & Msg.SentOn, vbOKOnly, "Priority Email" 'Msg.Subject & vbCrLf & Msg.Body
        ElseIf Msg.SenderEmailAddress Like "*abc.com*" Or Msg.CC Like "*abc.com*" Then
            MsgBox "This is a priority email" & vbCrLf & "Subject: " & Msg.subject & vbCrLf & "At: " & Msg.SentOn, vbOKOnly, "Priority Email" 'Msg.Subject & vbCrLf & Msg.Body
                        
        End If
    End If
        
ProgramExit:
    Exit Sub
ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Resume ProgramExit
End Sub

【问题讨论】:

  • 您已通过添加 MsgBox 阻止了代码。允许代码完成以处理后续邮件的一种可能方法是向传入邮件添加一个类别。
  • @niton:我真的很抱歉,因为我对 VBA 不是很好,而且我无法理解“添加类别”。你能详细说明一下吗?
  • 将 MsgBox 代码替换为 Msg.Categories = "Priority Email",后跟 Msg.save。必要时更改视图以显示类别。

标签: vba outlook


【解决方案1】:

对于不阻止 ItemAdd 代码的提示:

dim priorityMail as mailitem

Set priorityMail = CreateItem(olMailItem)
With priorityMail
    .Subject = This is a priority email & Msg.subject
    .Body = "At: " & Msg.SentOn & vbCrLf & vbCrLf & Msg.Body
    .display
End With

【讨论】:

    猜你喜欢
    • 2013-10-28
    • 2016-02-08
    • 2015-09-02
    • 1970-01-01
    • 2019-12-25
    • 2010-11-20
    • 2015-10-13
    • 2012-05-03
    • 1970-01-01
    相关资源
    最近更新 更多