locked
Automatic reply on incoming messages in outlook using VBA RRS feed

  • Question

  • I want to automatic reply on same email.
    For example: 
    If subject of incoming message particular person/recipient. i need automatic reply on that message with text in the body "xxxxx" rply on same email.
    • Edited by pbpver1 Thursday, August 8, 2013 1:25 PM
    Thursday, August 8, 2013 1:24 PM

All replies

  • I want to automatic reply on subject.
    For example: 
    If subject of incoming message particular person/recipient. i need automatic reply on that message with text in the body "xxxxx" rply on same email.
    • Merged by Jeffrey_Chen_ Friday, August 9, 2013 1:54 AM duplicated post thread
    Thursday, August 8, 2013 1:22 PM
  • This is a duplicated thread - perhaps you could remove the other copy?

    Provided Outlook is running at the time (there are more possibilities with Exchange Server accounts) then a simple macro script run from a Rule to identify the messages in question will do the job e.g. as follows

    The second 'Test' macro is to enable you to test the results Select a message and run the test macro.

    Option Explicit

    Sub AutoReply(olItem As Outlook.MailItem)
    Dim olOutMail As Outlook.MailItem
        With olItem
            Set olOutMail = olItem.Reply
            With olOutMail
                .Body = "This is the reply text"
                .Display        'Change to .Send after testing
            End With
            Set olOutMail = Nothing
        End With
    End Sub

    Sub Test()
    Dim olMsg As MailItem
    On Error Resume Next
    Set olMsg = ActiveExplorer.Selection.Item(1)
    AutoReply olMsg
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com


    Thursday, August 8, 2013 2:00 PM
  • Why VBA and why not a simple Outlook Rule?
    Thursday, August 8, 2013 6:35 PM
  • List of people is huge
    Monday, August 12, 2013 11:03 AM
  • Thanks Graham.

    But for above code, missing one small portion. if im receiving from particular person/recipient i need. can you pls help me on it.

    Monday, August 12, 2013 11:06 AM
  • Can you help me in amending above code? 

    Note: This replies should only for specific people.

    Public WithEvents myOlItems As Outlook.Items declared at top level.

    Private Sub myOlItems_ItemAdd(ByVal Item As Object)
        
        Dim MsgReply As Outlook.MailItem
        Set olApp = Outlook.Application
        Set objMail = olApp.CreateItem(olMailItem)
             
        With MsgReply
            .To = Item.SenderName
            .Subject = "Re " & Item.Subject
            .HTMLBody = "<span style=""font-family : verdana;font-size : 10pt""><p>Hello " & .To & " <p><p><p> Thank you for contacting the Support Centre <p><p><p> Your email has been received with the description of: " & Item.Subject & "  </p></span>" & .HTMLBody
            .Send
        End With
        
         
        Set olApp = Nothing
        Set objMail = Nothing 
    End Sub

    Tuesday, August 13, 2013 3:35 PM
  • ha ha rely its funny. i think no body knows. :)
    Wednesday, August 21, 2013 10:23 AM
  • The original macro Sub AutoReply(olItem As Outlook.MailItem) was intended to be run from a rule. If you want that rule to apply to only certain people then setup the rule to only act on messages from those people. The test macro works on any message.

    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, August 21, 2013 1:52 PM
  • Dear Graham Mayor,

    I have used the rule to run as a script for below coding about autoreply in Outlook 2010 which connected to Exchange Server 2010. I have some issues as below, hopeful can give some advice:

    1. The coding can work in 1 PC but can't work in 1 PC, which setting should I check so that the coding can work in all PCs?

    2. If the sender send one email, I find the coding continue to reply more than 1 autoreply email and repeat many times, it stop until I stop to run rule. which coding should modify in order to autoreply 1 time only?

    3. if I want to autoreply with outlook template (include subject, content, signature and company logo), which  coding should modify to support this? 

    Option Explicit

    Sub AutoReply(olItem As Outlook.MailItem)
    Dim olOutMail As Outlook.MailItem
        With olItem
            Set olOutMail = olItem.Reply
            With olOutMail
                .Body = "This is the reply text"
                .Send        
             End With
            Set olOutMail = Nothing
        End With
    End Sub

    Sub Test()
    Dim olMsg As MailItem
    On Error Resume Next
    Set olMsg = ActiveExplorer.Selection.Item(1)
    AutoReply olMsg
    End Sub

    Thank you very much for your help and attention.

    Best Regards,
    Stanley

    Wednesday, August 2, 2017 4:44 PM
  • 1. The coding can work in 1 PC but can't work in 1 PC, which setting should I check so that the coding can work in all PCs?

    What do you mean? The code I posted is individual to the PC replying to the message, so the code and the rule that calls it should be applied to each PC as appropriate.

    As you are running Exchange Server, I would have thought that auto-responses were something better applied at the server? See https://blogs.technet.microsoft.com/exchange/2011/09/08/configure-automatic-replies-for-a-user-in-exchange-2010/


    Graham Mayor - Word MVP
    www.gmayor.com

    Thursday, August 3, 2017 3:34 AM
  • Dear Graham Mayor, Thanks for your reply.The same coding can work in Outlook 2010 in one pc and cannot work in Outlook 2010 in another pc. I think may be the Outlook settings between these 2 PCs. Which swtting should I checked? Also, I would be grateful if some suggestions can be provided for questions 2 and 3 that I asked on 2 Aug 2017. Thank your very much for your help and attention. Best Regards, Stanley Chan
    Thursday, August 3, 2017 5:58 AM
  • If it works on one PC but not on another then you will probably need to create a self certificate on the other PC - see

    The code will run for every message that it applies to as configured in the rule.

     If you associate a signature with the e-mail account, then that should be added to the reply automatically.

    Graham Mayor - Word MVP
    www.gmayor.com

    Thursday, August 3, 2017 9:05 AM
  • Thanks for the valuable information. I used the rule in outlook 2010  (Apply this rule after the message arrives -> sent only to me-> and on this computer only -> run autoreply (i.e. script as below):

    Option Explicit

    Sub AutoReply(olItem As Outlook.MailItem)
    Dim olOutMail As Outlook.MailItem
        With olItem
            Set olOutMail = olItem.Reply
            With olOutMail
                .Body = "This is the reply text"
                .Send        
             End With
            Set olOutMail = Nothing
        End With
    End Sub

    Sub Test()
    Dim olMsg As MailItem
    On Error Resume Next
    Set olMsg = ActiveExplorer.Selection.Item(1)
    AutoReply olMsg
    End Sub

    The above code will continue to autoreply more than 1 reply even the sender send only message/email only. The autoreply stop only when stop the rule. How should modify the code to fix the above issue? Also, if  .Body content include Chinese wording, English wording and company logo, how to modify code in .Body content or use Outlook template as reply content?

    Thank you very much for your help and attention.

    Thursday, August 3, 2017 4:30 PM
  • I am not sure what you mean by 'continue to send'. If the code is associated with a rule, it will reply to every message the rule applies to for as long as the rule is active.

    There is no facility to reply to a message using a template, though you can do so by means of a subterfuge e.g. the following replaces the reply body with the body from the named template

    Sub AutoReply(olItem As Outlook.MailItem)
    Dim olOutMail As Outlook.MailItem
    Dim oTemp As Outlook.MailItem
    Dim fso As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        If fso.FileExists("D:\Word 2016 Templates\templatename.oft") Then    'the name and path of the template
            Set oTemp = CreateItemFromTemplate("D:\Word 2016 Templates\templatename.oft")
            With olItem
                Set olOutMail = olItem.Reply
                With olOutMail
                    .HTMLBody = oTemp.HTMLBody
                    .Send
                End With
                Set olOutMail = Nothing
            End With
            oTemp.Close olDiscard
        Else
            MsgBox "Template not found!"
        End If
    End Sub

    You can edit the message body directly, but I have enough trouble with English without having to take Chinese into account.  :)


    Graham Mayor - Word MVP
    www.gmayor.com

    • Proposed as answer by Stanleycha Saturday, August 5, 2017 4:58 PM
    Friday, August 4, 2017 4:23 AM
  • I have solved the issue about continue to send autoreply email due to I have used my email address to test.

    After use subterfuge, the autoreply content can use outlook template but not apply to subject field and company logo image in outlook template. How to also include subject field and company logo in outlook template for autoreply content if possible? 

    Also, if I want to know more details coding for Outlook VBA especially for autoreply, which website (e.g. Outlook VBA Developer/programming guide) can I refer to?  

    Thanks for your help.

    Saturday, August 5, 2017 4:51 PM
  • Dear Graham Mayor,

    Thanks for your help. My Outlook 2010 (connected to Exchange server 2010) can access my personal email and shared mailbox, how to I use rule and run as a script to apply autoreply for shared mailbox? Can I use the same autoreply rule used in personal mail to shared mailbox? Do I need full access permission for shared mailbox in order to create autoreply rule?

    Thanks for your help again.

    Regards,
    Stanley

    Tuesday, August 8, 2017 4:53 PM
  • Hi Graham,

    Can you please suggest on how to save the email subject into an Oracle sql table?

    Thank you.

    Wednesday, April 25, 2018 7:25 AM
  • Hello. How can I configure the "exchange 2010" or "Outlook 2013" auto-reply to mail. But not to the sender’s mail, but to the mail indicated in the message body.
    Thursday, October 31, 2019 6:10 AM