Reputation: 25
At work, when we send out an e-mail we have to type in the BCC field a certain address as well as click on the "message options" and type in "direct replies to:" another address.
I want to add a button to the ribbon that will: Open up a reply based on the e-mail I have highlighted in the "inbox" pane, automatically add the e-mail to the BCC field AND automatically set the message to "direct replies to:"
So far I have come up with this:
Sub ReplyUW()
Dim mail As MailItem
Set mail = ActiveInspector.CurrentItem
mail.ReplyRecipients.Add ("[email protected]")
mail.ReplyRecipients.Add ("[email protected]")
mail.Recipients.ResolveAll
End Sub
This sets it up to "direct replies to:" but only if I have the message opened.
Upvotes: 2
Views: 2781
Reputation: 53643
Let's start with something like this. As I mentioned in the comments, you can use the ActiveExplorer
instead of the ActiveInspector
. This macro is set up to run on all selected items, so you could select more than one email, and "reply" to all of them automatically.
Sub test()
Dim m As MailItem 'object/mail item iterator
Dim recip As Recipient 'object to represent recipient(s)
Dim reply As MailItem 'object which will represent the reply email
'Loop over each SELECTED item:
For Each m In Application.ActiveExplorer.Selection
If m.Class = olMail Then
Set reply = m.reply
'Adds a "direct replies to" address:
reply.ReplyRecipients.Add "[email protected]"
'Adds BCC recipient to the reply:
Set recip = reply.Recipients.Add("[email protected]")
recip.Type = olBCC '3
reply.Save 'saves a draft copy to your SENT folder
reply.Send
End If
Next
End Sub
Credit where it's due, I did not know how to add a BCC recipient, but I found out how to do that here:
Add BCC to email with VBA in Outlook 2013
Adding a button to the ribbon is probably more involved and is certainly more complicated than maybe necessary, and if you do desire to do that, I would recommend it should be a new question. Ribbon/XML customization is not "simple" VBA anymore.
For the time being, if you simply enable the Developer ribbon, then you can access this macro from the Macros menu:
Upvotes: 2