【问题标题】:Detect whether an email is currently being edited in Outlook?检测当前是否正在 Outlook 中编辑电子邮件?
【发布时间】:2020-06-21 05:49:45
【问题描述】:

我有一个在 Application_NewMail 事件上运行的宏 - 但我发现如果用户当前正在撰写电子邮件或回复,它会产生奇怪的影响 - 有时会导致 Outlook 崩溃并失去他们的进度。

有没有一种方法可以检测用户当前是否正在撰写电子邮件?

这将允许我取消宏并避免打扰用户。

【问题讨论】:

标签: vba outlook


【解决方案1】:

我能够从相关问题中找到零碎的信息,但没有考虑到弹出式电子邮件编辑器和内联响应。这是我汇总的解决方案(似乎涵盖了所有基础):

Private Function IsUserEditing() As Boolean
    ' Check if the user is composing an email. Don't interrupt them if we are.
    ' 1. Check if the user has the pop-up email 'inspector' window open
    If Not (Application.ActiveInspector Is Nothing) Then
        Dim OpenWindow As Variant
        Set OpenWindow = Application.ActiveInspector.CurrentItem
        If TypeOf OpenWindow Is MailItem Then
            Dim NewMail As MailItem
            Set NewMail = OpenWindow
            ' Check if the mail they're viewing is not 'Sent' (i.e. being edited)
            If Not (NewMail.Sent) Then
                IsUserEditing = True
                Exit Function
            End If
        End If
    ' 2. Check if the user is replying to an email using the 'inline response' feature
    ElseIf Not (Application.ActiveExplorer.ActiveInlineResponse Is Nothing) Then
        IsUserEditing = True
        Exit Function
    End If
    IsUserEditing = False
End Function

可以这样使用:

Private Sub Application_NewMail()
    Debug.Print "New mail received..."        
    ' Check if the user is composing an email. Don't interrupt them if we are.
    If IsUserEditing Then
        Debug.Print "User appears to be composing an email. Cancelling..."
        Exit Sub
    End If        
    ' Otherwise Proceed
    PerformOnNewMailActions
End Sub

希望这对其他人有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-11
    • 2023-04-07
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 2011-09-05
    相关资源
    最近更新 更多