如何在Outlook 2007中使用宏更改replyTo地址?

时间:2015-01-15 14:26:35

标签: vba outlook

我正在使用Outlook 2007.我只想编写一个宏来删除所有收件人并添加一个新收件人。这是我的代码:

Sub replyTo(item As Outlook.MailItem)
    Do While item.ReplyRecipients.Count() > 0
        item.ReplyRecipients.Remove (1)
    Loop
    item.ReplyRecipients.Add ("example@example.com")
    item.ReplyRecipients.ResolveAll
End Sub

我还创建了一个运行此脚本的规则。不幸的是,当我收到邮件时,回复邮件并没有变成我想要的东西。

1 个答案:

答案 0 :(得分:1)

目标不明确,但......

Sub replyToExampleImmediately(item As Outlook.mailitem)

' Ignore the sender of the item and reply to "example@example.com"

    Dim replyItem As mailitem
    Set replyItem = item.reply

    replyItem.Recipients.Remove (1)

    replyItem.Recipients.Add ("example@example.com")
    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 "example@example.com"

    Dim replyItem As mailitem
    Set replyItem = item.reply

    replyItem.ReplyRecipients.Add ("example@example.com")
    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