• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Reply using the address a message was sent to

Slipstick Systems

› Developer › Reply using the address a message was sent to

Last reviewed on May 24, 2018     29 Comments

Use this code to send a new message using the address the selected message was sent To as the send using From account.

See Using a Gmail Master Account: Reply using the Correct Account for instructions and an automated set of macros. It will work with any service that collects mail sent to other accounts.

This code is for people who use an account such as Gmail or Outlook.com to collect mail from other accounts and download only that account. Outlook will always reply using the account that downloaded the message, which is the Outlook.com or Gmail account. You'll need to create an account in Outlook for the other addresses to use this code, but can set the accounts to never download email.

This code gets the address the message was sent to and looks for an existing account with the same display name and uses that account. If it can't find a matching account it uses the account that downloaded the message. This could be changed to use the default account in your profile.

Update: I fixed the macro, it now checks for a specific string (an email address) in the To field. If it finds the address, the reply is from that address, otherwise the reply is from the default address. If you need to check for one of several accounts, you'll need to use an array.

To force the code to always use a specific non-default account, change this line:
objMsg.SendUsingAccount = olNS.Accounts.Item(1) to
objMsg.SendUsingAccount = olNS.Accounts.Item(2) where 2 is the placement of the account in the Account Settings list
or objMsg.SendUsingAccount = "Display name of desired account"

If you are using Exchange server and have Send as permission to the address a message was sent to (such as a distribution list), replace the For Each... Next block with:
objMsg.MailItem.Sender = oMail.To
or
objMsg.SentOnBehalfOfName = oMail.To

This may not work with Outlook 2013's "inline replies". Messages will be opened in a new Window.

Reply from the address a message was sent to

Public Sub AccountSelection()
Dim oAccount As Outlook.Account
Dim strAccount As String
Dim olNS As Outlook.NameSpace
Dim objMsg, oMail As MailItem
 
Set olNS = Application.GetNamespace("MAPI")
 
' For a reply all version, replace Reply with ReplyAll 
Set objMsg = ActiveExplorer.Selection.Item(1).Reply
 
If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
 Set oMail = ActiveExplorer.Selection.Item(1)
  
 On Error Resume Next
 
For Each Recipient In oMail.Recipients
 strRecip = Recipient.Address & ";" & strRecip
Next Recipient
 
 
If InStr(strRecip, "alias@domain1.com") = 1 Then
' StrAccount is the account name as shown in the Account Settings list
strAccount = "alias@domain1.com"
Else
End If
  
 For Each oAccount In Application.Session.Accounts
  If oAccount.DisplayName = strAccount Then
     objMsg.SendUsingAccount = oAccount
       Else
 
     ' to reply using the account that downloaded the message
     ' leave the objMsg line commented
     ' remove comment to reply using default account
     ' objMsg.SendUsingAccount = olNS.Accounts.Item(1)
 
  End If
Next
 
  objMsg.Display
 
Else
 
End If
 
Set objMsg = Nothing
Set olNS = Nothing
End Sub

Check for multiple aliases

This version of the macro, updated by Victor Beekman, checks for multiple aliases.

Public Sub AccountSelection()
Dim oAccount As Outlook.Account
Dim strAccount As String
Const strAlias1 = "alias1@somedomain.xxx"
Const strAlias2 = "alias2@somedomain.xxx"
Dim strRecip As String
Dim olNS As Outlook.NameSpace
Dim objMsg, oMail As MailItem
Dim Recips As Object
Dim i As Long

Set olNS = Application.GetNamespace("MAPI")
' to integrate with replyall button see https://www.slipstick.com/developer/remove-address-reply/
' For a reply all version, replace Reply with ReplyAll
Set objMsg = ActiveExplorer.Selection.Item(1).ReplyAll
 
 On Error Resume Next
 
Set Recips = objMsg.Recipients
For i = Recips.Count To 1 Step -1
  If LCase(Recips.Item(i).Address) = strAlias1 Then
     strAccount = strAlias1
     Recips.Remove i
  ElseIf LCase(Recips.Item(i).Address) = strAlias2 Then
     strAccount = strAlias2
     Recips.Remove i
  End If
Next i
  
 
If InStr(strRecip, strAlias1) = 1 Then
' StrAccount is the account name as shown in the Account Settings list
    strAccount = strAlias1
ElseIf InStr(strRecip, strAlias2) = 1 Then
    strAccount = strAlias2
End If
  
For Each oAccount In Application.Session.Accounts
  If oAccount.DisplayName = strAccount Then
     objMsg.SendUsingAccount = oAccount
       Else
      ' to reply using the account that downloaded the message
     ' leave the objMsg line commented
     ' remove comment to reply using default account
     ' objMsg.SendUsingAccount = olNS.Accounts.Item(1)
   End If
Next
objMsg.Display

Set objMsg = Nothing
Set olNS = Nothing
End Sub

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.
  3. Click Run to test the macro

When you're happy with the macro, create a ribbon or QAT button for the macro.

More information as well as screenshots are at How to use the VBA Editor

Reply using the address a message was sent to was last modified: May 24th, 2018 by Diane Poremsky
Post Views: 42

Related Posts:

  • Assign an Email Account to an Outlook Contact
  • Choose the account to send a reply from
  • Macros to send messages using a specific account
  • Foward a Message and CC the Original Recipients

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Comments

  1. Estelle says

    October 14, 2021 at 10:10 am

    Hi Diane, I have 2 outlook accounts including 1 imap account that is automatically transferred to my outlook.com account.
    I would like that when I click on reply to an email sent to my imap account in my outlookaccount folder that the from field is "imap account" instead of exchange account and that I have a BCC field at a third address. I use in thisoutlook session a code that works for the BCC without worry. 
    What can I do?
    I also used a module but it requires me to click on the module instead of "reply to" which is not very convenient. Thanks in advance.

    Translated with http://www.DeepL.com/Translator (free version)

    Reply
  2. Paolo says

    September 25, 2014 at 12:33 pm

    Hi Diane, I try to use this macro to set the from field with the distribution group address as you suggest using Outlook 2013 on Windows 7 pro 32 bit, (the formsadmin doesn't work well with it), but the field remains the same.
    Thanks for your time.

    Reply
    • Diane Poremsky says

      October 2, 2014 at 12:23 pm

      in exchange, you need to use the exchange alias or x500 address here:
      If InStr(strRecip, "alias@domain1.com")

      This will get the sender's address from a selected item. I prefer using /cn=alias part instead of just alias, but it can include a long string of number, at least with office 365 mailboxes.

      Public Sub Getx500Address()
      Dim objMail As Object
      Set objMail = Application.ActiveExplorer.Selection.Item(1)
      MsgBox objMail.SenderEmailAddress
      Set objMail = Nothing
      End Sub

      Reply
  3. Tim says

    August 17, 2014 at 7:44 pm

    Hi
    This Macro works well in specifying the correct account - thank you, however it does not pick up the Signature for that account in the reply text.
    It still uses the default Signature.
    Any thoughts on how to change the macro so it selects the correct Signature ?
    Thanks

    Reply
    • Diane Poremsky says

      August 17, 2014 at 9:59 pm

      You'll need to insert it using the macro - I don't have any code handy that does that though.

      Reply
  4. Fabio says

    May 24, 2014 at 5:48 am

    Ok... Now you got me, what's an inspector?

    Reply
    • Diane Poremsky says

      May 24, 2014 at 1:36 pm

      it's how vba refers to an open item. A code example is here - https://www.slipstick.com/developer/vba-disable-outlook-2010-no-subject-warning/
      this sample works with open or close: https://www.vboffice.net/en/developers/inspector-wrapper-receive-events-of-multiple-emails

      Reply
  5. Fabio says

    May 23, 2014 at 7:52 pm

    Duh!...thanks Diane...I'd probably still be typing ".Category"...for those of you who want to know. I added the following to this macro.

    ' Set Category
    objMsg.Categories = "Sent By Fabio"
    objMsg.Save

    The reason I did it was due to the fact that my company is using Google Apps and because I'm using outlook in my office PC and my laptop, I have to use the "recent:" setting (recent:fabio@mydomain.com) on both machines, so I can make sure I get emails in both machines. Google mail seems to ignore the POP setting to leave messages on the server so it can be retrieved by another machine and IMAP doesn't work too well. The problem is that you get a duplicate of every email you sent into your inbox and when you're responding to lots of emails from clients (along with other co-workers using the same email aliases --- we really need a ticketing system but the boss thinks it's unnecessary). Anyway, I needed to identify the messages I sent versus the messages my co-workers sent, so I couldn't filter via the incoming email address otherwise I might miss one of their responses. So assigning a category only to the messages I sent allows one of my rules to delete incoming messages with this category, after all I already have a copy of the message I sent in my sent items folder -- I don't need another copy!

    Now if, I could auto assign a category every time I click a NEW email so my rule would work for my own messages (not using one of the aliases) everything would be perfect. Still, I can at least filter messages coming from my own email in a separate rule, so it's not so bad.

    Reply
    • Diane Poremsky says

      May 23, 2014 at 9:50 pm

      you can but need to use an inspector. i'll see if i can find a code sample, im sure i have something here. Or you could use a macro instead of the New button...

      Reply
  6. Fabio says

    May 22, 2014 at 8:29 pm

    To expand on this Macro, I wanted to include a specific Category every time I send from this Macro but I can't seem to do it. I thought it was simple as:

    .Category = "Sent from Reply Macro"

    Obviously the Category has already been created. I saw a few examples where a macro can display a list of categories to choose from but I can't seem to just set one without having to choose.

    I'm not an expert on vb, so that might be the problem ;-)

    -Fabio

    Reply
    • Diane Poremsky says

      May 22, 2014 at 9:17 pm

      it's .categories, not .category.

      Reply
  7. Michael says

    March 17, 2014 at 11:59 am

    Diane, Found one more weird thing. If the email is sent to me ONLY (example To: a@b.com) the macro works.

    However, if it is To: a@b.com; differentemail@c.com then it does not work. As in, if my email is only one of multiple addresses it does not work.

    What would I need to modify to say if my email address is anywhere in the To: field then apply this rule?

    Reply
    • Diane Poremsky says

      March 17, 2014 at 11:44 pm

      This: If InStr(strRecip, "alias@domain1.com") = 1 Then detects your address within the recipient string. Try > 0 instead of = 1

      Is the case the same each time? If not, use the lcase function to force it to lower case - InStr(lcase(strRecip), "alias@domain1.com")

      Reply
  8. Michael says

    March 17, 2014 at 2:05 am

    That fixed it!!! Thanks so much

    Reply
  9. Michael says

    March 16, 2014 at 9:53 pm

    Did you retest? I have now tried on three different computers with the most recent Outlook 2013 with all updates on Windows 8.1. None of them are working.

    Reply
    • Diane Poremsky says

      March 17, 2014 at 12:16 am

      Change the last Dim line to this: Dim objMsg As MailItem, oMail As MailItem - the missing as Mailitem is the problem.

      Reply
  10. Michael says

    March 12, 2014 at 4:53 am

    Thanks so much!!! If there is anything I can do to provide data I will -- just shoot me an email and I can send screenshots or anything.

    Reply
  11. Michael says

    March 12, 2014 at 1:06 am

    Are you using Office 2013? I just can't seem to make it work no matter what I do!

    Reply
    • Diane Poremsky says

      March 12, 2014 at 1:22 am

      It was tested in both 2010 and 2013. I'll retest it, it's possible an update changed something - another person is having problems using accounts in a macro too.

      Reply
  12. Fabio Quintal says

    March 3, 2014 at 6:29 pm

    I know this is an old post but I wanted to thank Diane for posting this macro.

    Diane:

    This worked perfectly for me, I tend to read most of my mail on the default reading pane (as opposed to opening the email completely -which doesn't work). I actually created three different Macros for REPLY, REPLY ALL, and FORWARD and replaced the buttons on the ribbon so I wouldn't click them by mistake. The only change (besides the obvious changes) I added a line "strRecip = LCase(strRecip)" because I noticed the Macro would not work correctly if the person used uppercase when typing the email address...for example if they typed it as info@mydomain.com it would work fine but if they typed it as Info@mydomain.com or INFO@mydomain.com or even the domain itself it would NOT work. With this addition everything works!

    Ascar Omarov:

    In case you're still looking for the Forward...just replace the line:

    Set objMsg = ActiveExplorer.Selection.Item(1).Reply

    with

    Set objMsg = ActiveExplorer.Selection.Item(1).Forward

    And everything should work for forwarding.

    Reply
  13. Ascar Omarov says

    June 10, 2013 at 4:57 am

    Derik, may I ask you to share the modified code which includes the Forward function? Did you try to make the Reply All and Forward as Attachment functions to work as well?

    Reply
  14. Derik du Plessis says

    April 4, 2013 at 5:08 am

    Diane, i have just experiment more, the above indicated actually has nothing to do with the macros, instead by changing the option indicated this affected an add in that i have called SAM, and that activates the correct sending account. Sorry about the confusion.

    Regards

    Reply
    • Diane Poremsky says

      April 4, 2013 at 7:01 am

      Yeah, I wasn't thinking either. I was trying to automate it last night so it would capture the Reply button and that will not work with inline replies (that is a limitation of the new feature) - but that macro would be totally different than this one (and it was not working as expected either).

      Reply
  15. Derik du Plessis says

    April 4, 2013 at 3:22 am

    As i do not like answering email or creating new ones in the actual reading pane, i changed the setting in options/mail/replies and forwards to always open in a new window (first check box) and now the macros run automatically and i am always presented with the correct mail account to use when answering emails. This works for both the ribbon as well as inline "Reply", "Reply All" and "Forward" buttons. Please do not ask me why, as MS is sometimes a black art.

    Any idea how i can get the same funcionality when creating a new meeting invitation?

    Reply
    • Diane Poremsky says

      April 4, 2013 at 6:34 am

      A lot of macros won't work on inline replies - it's how the inline replies are handled in the object model.

      I'm not sure I understand the meeting question.

      Reply
  16. Derik du Plessis says

    April 3, 2013 at 3:16 pm

    This is great as it is exactly what i needed. I also modified the macro to include a forward version. However the macros does not run when i press the Reply, Reply All or Forward buttons either on the ribbon or the "inline" buttons they do run successfully when i execute them from the developer pane or the macro pane. How can i get them to run automatically?

    Once again, thanks for this great macro!!

    Reply
    • Diane Poremsky says

      April 3, 2013 at 4:28 pm

      You need to create a ribbon button for the macro - it doesn't watch for the buttons to be clicked.

      Reply
  17. Peauxboy says

    January 21, 2013 at 9:02 am

    This is EXACTLY what I am looking for!!! I think. I'd like to use this so that customer service representatives always respond with my companies support email when responding to messages in a specific public folder instead of their own without requiring them to remember to change the From field. My only problem is how do I implement this? In other words, what do I need to do so that this is used?

    Thanks so much!

    Reply
    • Diane Poremsky says

      January 21, 2013 at 8:26 pm

      Because its a public folder, i don't think that one will work. It looks at accounts in the Accounts list. You either need to use a macro with the MailItem.Sender Property or the choose from account macro.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 7

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Change Outlook's Programmatic Access Options
  • Use Public Folders In new Outlook
  • Removing Suggested Accounts in New Outlook
  • How to Delete Stuck Read Receipts
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.