none
Changing Outlook Account Based on Recipient - Problem RRS feed

  • Question

  • I have this macro below:

     

     

     

    Public Sub New_Reply()
    
    Dim objApp As Outlook.Application
    Dim oAccount As Outlook.Account
    Dim oMail As Outlook.MailItem
    
    
    Set objApp = CreateObject("Outlook.Application")
    On Error Resume Next
    
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set oMail = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set oMail = objApp.ActiveInspector.CurrentItem
        Case Else
    End Select
    
    
    Dim recip As Outlook.Recipient
    Dim ae As Outlook.AddressEntry
    
    Set recip = oMail.Recipients.Item(1)
    Set ae = recip.AddressEntry
    
    Dim sAddress As String
    sAddress = ae.Address
    
    
    Select Case sAddress
        Case "support@domain1.com"
            For Each oAccount In Application.Session.Accounts
                If oAccount = "Support" Then GoTo EndCode
            Next
        Case "sales@domain1.com"
            For Each oAccount In Application.Session.Accounts
                If oAccount = "Sales" Then GoTo EndCode
            Next
        Case "info@domain2.com"
            For Each oAccount In Application.Session.Accounts
                If oAccount = "Another Support" Then GoTo EndCode
            Next
    End Select
    
    
    EndCode:
        Set oMail = Application.ActiveExplorer.Selection(1).Reply
        oMail.SendUsingAccount = oAccount
        oMail.Display
    End Sub
    
    

    This does indeed work for changing the account.  However, it messes up the signatures associated with the account.  Not only does it not change the signature to the default for the account, but it also seems to corrupt the signature setup so that it does not change when switching accounts manually also.  Does anyone know the fix to make this work properly?  Thanks much in advance.

     




    Monday, August 1, 2011 4:10 AM

Answers

  • Hi Mystik

     

    Looking at the issue from an Outlooks perspective...

    > You have a macro...which sends mail with mutiple from address and also with proper signature with OL2010

    The same is not happening with the Ol2k7 correct?

    Does this looks like because of the feature @ OL2010 "Multiple Exchange accounts"

    http://technet.microsoft.com/en-us/library/cc179110.aspx

    Multiple Exchange accounts

    Outlook 2010 can connect to multiple Exchange accounts at the same time. The Exchange accounts can be in the same or different domains or servers

     

    Conclusion: We wont be able to get the same @ OL2k7.

     

    Cheers

    Aravind

    Wednesday, August 17, 2011 2:54 AM

All replies

  • Hello,

    Try replying via MailItem.Actions("Reply").Execute instead of MailItem.Reply. Does it help?


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, August 1, 2011 8:56 AM
  • When I change oMail.Display to oMail.Actions("Reply").Execute, the reply window does not seem to show.

    Monday, August 1, 2011 1:58 PM
  • Get the value returned by oMail.Actions("Reply").Execute, cast it to MailItem and then call MailItem.Display.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Monday, August 1, 2011 4:33 PM
  • Thank you very much for your efforts in helping me.  Much appreciated.  This is what I tried:

        Set oMail2 = oMail.Actions("Reply").Execute 'Application.ActiveExplorer.Selection(1).Reply

        oMail2.SendUsingAccount = oAccount

        oMail2.Display

    oMail2 is dimmed as:

    Dim oMail2 As Outlook.MailItem
    The reply window is shown now, but the issue remains the same as before (wrong signature and unable to change manually). Any other thoughts perhaps? Or did I not do it correctly?

    Monday, August 1, 2011 7:30 PM
  • Hi Mystik,

     

    Thanks for posting in the MSDN Forum.

     

    Would you please tell me your Outlook version?

     

    I use Outlook 2010 on my side. I don’t see the situation which you mentioned. At least I can change the SendUsingAccount via manual way.

     

    Have I misunderstood something?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 3, 2011 3:40 AM
    Moderator
  • I am using Office 2007 with the code above (or tweaks mentioned).  Thanks again for any help.  Really hoping to get this going.  :)
    Wednesday, August 3, 2011 6:39 PM
  • Hi Mystik,

     

    Would you please try to you If oAccount.DisplayName = "xxx@xxx.com" Then GoTo EndCode in you snippet. Let’s see whether it can work.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 5, 2011 2:51 AM
    Moderator
  • The select cases are working since the account is indeed being changed correctly.  The trouble is that the signature does not change, unfortunately.

    Friday, August 5, 2011 5:13 AM
  • However, I did try what you said anyway.  The account is not changed with this route.


    Friday, August 5, 2011 5:16 AM
  • Hi Mystik,

     

    I think I have no idea about it. I will consult senior engineers for help. I will take some time for response. Thanks for your understanding and supporting.

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 8, 2011 2:38 AM
    Moderator
  • Thank you.  Hoping to hear back with a solution soon.  Much appreciated.  
    Monday, August 8, 2011 4:17 PM
  • Hi Mystik

     

    Looking at the issue from an Outlooks perspective...

    > You have a macro...which sends mail with mutiple from address and also with proper signature with OL2010

    The same is not happening with the Ol2k7 correct?

    Does this looks like because of the feature @ OL2010 "Multiple Exchange accounts"

    http://technet.microsoft.com/en-us/library/cc179110.aspx

    Multiple Exchange accounts

    Outlook 2010 can connect to multiple Exchange accounts at the same time. The Exchange accounts can be in the same or different domains or servers

     

    Conclusion: We wont be able to get the same @ OL2k7.

     

    Cheers

    Aravind

    Wednesday, August 17, 2011 2:54 AM