我想使用这个我偷了""来自互联网。 (至少我是诚实的......)
在回复电子邮件时,它会在主题行中添加关键字。
在发送电子邮件时它按预期工作但当我取消消息窗口时,该功能会停止触发,直到我重新启动Outlook。
为什么表现如此?我试图调试它没有任何运气... 任何人都可以帮我解决这个问题吗?
ThisOutlookSession中的代码
Option Explicit
Private WithEvents oExpl As Explorer
Private WithEvents oItem As MailItem
Private bDiscardEvents As Boolean
'//slipstick.me/44b0w
Private Sub Application_Startup()
Set oExpl = Application.ActiveExplorer
bDiscardEvents = False
End Sub
Private Sub oExpl_SelectionChange()
On Error Resume Next
Set oItem = oExpl.Selection.Item(1)
End Sub
' Reply
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
Cancel = True
bDiscardEvents = True
Dim oResponse As MailItem
Set oResponse = oItem.Reply
' add the fields here
oResponse.Subject = "keyword " & oResponse.Subject
oResponse.Display
bDiscardEvents = False
Set oItem = Nothing
End Sub
答案 0 :(得分:0)
不确定为什么你会收到错误;可能存在一些问题 - 可能与在sub的开头取消或使用“Set oItem = Nothing'”有关。另外bDiscardEvents似乎没有做任何事......
尝试以下方法:
在ThisOutlookSession
中
Private Sub olItem_Reply(ByVal Response As Object, Cancel As Boolean)
If AddKeywordToReply(olItem, "Test:") = True Then Cancel = True
End Sub
在模块中
Function AddKeywordToReply(oItem As MailItem, KeyWord As String) As Boolean
AddKeywordToReply = False
If oItem.Class = olMail Then
If Not oItem.sender Is Nothing Then
Dim oMsgReply As Outlook.MailItem
Set oMsgReply = oItem.Reply
oMsgReply.Subject = KeyWord & " " & oItem.Subject
oMsgReply.Display
Set oMsgReply = Nothing
AddKeywordToReply = True
End If
End If
End Function