我为已打开的邮件创建了一个宏,它可以执行某些操作。我想创建一个规则,当我打开邮件时,它会自动执行。
我不希望这条规则一直运行,就在我打开邮件时,我不想在我收到的每封邮件上强制执行此规则。
答案 0 :(得分:5)
关注@ZZA评论,
试试这段代码:
Public WithEvents myItem As Outlook.MailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail Then
Set myItem = Item
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
'Your code
End Sub
在ThisOutlookSession中粘贴代码
修改强>
为避免'Your code
触发事件,我们需要一个事件禁用器:
Public WithEvents myItem As Outlook.MailItem
Public EventsDisable as Boolean
Private Sub Application_ItemLoad(ByVal Item As Object)
If EventsDisable = True Then Exit Sub
If Item.Class = olMail Then
Set myItem = Item
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
EventsDisable=True
'Your code
EventsDisable=False
End Sub