2015-01-15 52 views
0

我正在使用Outlook 2007.我只想編寫一個宏,它將刪除所有收件人並添加一個新的收件人。這裏是我的代碼:如何在Outlook 2007中使用宏更改replyTo地址?

Sub replyTo(item As Outlook.MailItem) 
    Do While item.ReplyRecipients.Count() > 0 
     item.ReplyRecipients.Remove (1) 
    Loop 
    item.ReplyRecipients.Add ("[email protected]") 
    item.ReplyRecipients.ResolveAll 
End Sub 

我也創建了一個規則來運行這個腳本。不幸的是,當我收到一封郵件時,replyTo郵件並沒有改變成我想要的。

+1

我沒有看到任何代碼奇怪。我可以建議的唯一方法是在對郵件項目對象進行更改後調用Save方法。嘗試處理NewMailEx事件並執行相同的操作,它將允許您至少調試代碼。 –

回答

1

的目標不明確,但...

Sub replyToExampleImmediately(item As Outlook.mailitem) 

' Ignore the sender of the item and reply to "[email protected]" 

    Dim replyItem As mailitem 
    Set replyItem = item.reply 

    replyItem.Recipients.Remove (1) 

    replyItem.Recipients.Add ("[email protected]") 
    replyItem.Recipients.ResolveAll 

    replyItem.Display 

ExitRoutine: 
    Set replyItem = Nothing 

End Sub 


Sub replyTosender(item As Outlook.mailitem) 

' Reply to the sender of the item and 
' set the replyTo so the sender will reply to "[email protected]" 

    Dim replyItem As mailitem 
    Set replyItem = item.reply 

    replyItem.ReplyRecipients.Add ("[email protected]") 
    replyItem.Display 

    ' comment out later 
    ActiveInspector.CommandBars.ExecuteMso ("MessageOptions") 

ExitRoutine: 
    Set replyItem = Nothing 

End Sub 

Sub replyTo_test() 
' First open a mailitem 

Dim curritem As mailitem 
Set curritem = ActiveInspector.currentItem 

replyToExampleImmediately curritem 
replyTosender curritem 

End Sub 
+0

謝謝!有效。 –

相關問題