How to Auto Use Different Accounts Based on Whether Replying or Forwarding Specific Emails in Outlook

If you have several email accounts configured in your Outlook, sometimes you may want to use specific email accounts to reply or forward specific emails. This article will teach you how to automate it with Outlook VBA.

The previous article in our blog – “How to Send Emails from a Specific Account in Your Outlook”, has introduced a method to always use a specific email account for sending emails. But by that means, Outlook will send out all the emails using the specific account. That is to say, you cannot specify different accounts for sending different emails, for instance, using one account when forwarding specific emails and using another when replying specific emails. Thus, in response to this issue, here we will teach you a smart and handy approach, which will use VBA. Read on to get it in detail.

Auto Use Different Accounts Based on Whether Replying or Forwarding Specific Emails

Auto Use Different Accounts Based on Whether Replying or Forwarding Specific Emails

  1. For a start, launch you Outlook properly.
  2. Then press “Alt + F11” key buttons in Outlook main window.
  3. Next you will enter the VBA editor.
  4. Subsequently, you need to double click on the “ThisOutlookSession” project on the left side.
  5. After that, you ought to coy the following VBA codes into this project.
Public WithEvents objExplorer As Outlook.Explorer
Public WithEvents objMail As Outlook.MailItem
Public objAccounts As Outlook.Accounts
Public objAccount As Outlook.Account

Private Sub Application_Startup()
    Set objExplorer = Outlook.Application.ActiveExplorer
    Set objAccounts = Outlook.Application.Session.Accounts
End Sub

Private Sub objExplorer_SelectionChange()
    On Error Resume Next
    Set objMail = objExplorer.Selection.Item(1)
End Sub

Private Sub objMail_Reply(ByVal Response As Object, Cancel As Boolean)
    Dim objReply As Outlook.MailItem
 
    'Get the specific email
    'You can change the condition as per your needs
    If InStr(LCase(objMail.Subject), "datanumen") > 0 Then
       'Use the specific email account to reply
       For Each objAccount In objAccounts
           If objAccount.DisplayName = "johnsmith@datanumen.com" Then
              Set objReply = objMail.Reply
              objReply.SendUsingAccount = objAccount
              objReply.Display
           End If
       Next
       Cancel = True
    End If
End Sub

Private Sub objMail_Forward(ByVal Forward As Object, Cancel As Boolean)
    Dim objForward As Outlook.MailItem
 
    'Get the specific email
    'You can change the condition as per your needs
    If objMail.SenderEmailAddress = "frank@datanumen.com" Then
       'Use the specific email account to forward
       For Each objAccount In objAccounts
           If objAccount.DisplayName = "johnny@datanumen.com" Then
              Set objForward = objMail.Forward
              objForward.SendUsingAccount = objAccount
              objForward.Display
           End If
       Next
       Cancel = True
    End If
End Sub

VBA Codes - Auto Use Different Accounts Based on Whether Replying or Forwarding Specific Emails

  1. Later you need to sign this code.
  2. Then change your Outlook macro settings to allow digitally signed macros.
  3. Eventually you can restart Outlook to activate this VBA project. From now on, Outlook will automatically use the specific email accounts when you reply or forward specific emails.

Keep Prepared for PST Troubles

As Outlook is vulnerable, your PST file is also prone to corruption. Therefore, you have to keep well-prepared for all potential dangers, such as corrupt PST data. So, what you must do is to make consistent and regular backups for Outlook data. In addition, it is prudent to get hold of a potent repair tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.