【发布时间】:2020-06-21 05:49:45
【问题描述】:
我有一个在 Application_NewMail 事件上运行的宏 - 但我发现如果用户当前正在撰写电子邮件或回复,它会产生奇怪的影响 - 有时会导致 Outlook 崩溃并失去他们的进度。
有没有一种方法可以检测用户当前是否正在撰写电子邮件?
这将允许我取消宏并避免打扰用户。
【问题讨论】:
我有一个在 Application_NewMail 事件上运行的宏 - 但我发现如果用户当前正在撰写电子邮件或回复,它会产生奇怪的影响 - 有时会导致 Outlook 崩溃并失去他们的进度。
有没有一种方法可以检测用户当前是否正在撰写电子邮件?
这将允许我取消宏并避免打扰用户。
【问题讨论】:
我能够从相关问题中找到零碎的信息,但没有考虑到弹出式电子邮件编辑器和内联响应。这是我汇总的解决方案(似乎涵盖了所有基础):
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
希望这对其他人有所帮助!
【讨论】: