Changing Outlook Account Based on Recipient

Status
Not open for further replies.

mystik

Member
Outlook version
Email Account
POP3
Ref this article: http://www.slipstick.com/outlook/email/choose-the-account-to-send-a-reply-from/

First of all, I would like to say thank you for this to the person that wrote the article. It has helped me a lot, but also resulted in a problem I am hoping someone can help with. The email account is changing, but the signature does not change to the default one for the new account. Also, the email seems to be corrupted in a way since changing the account manually also now does not change the signature for this email. I am using Outlook 2007. Any ideas? Thanks much in advance! Here's my code in case it is helpful...

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 = "2nd Support" Then GoTo EndCode
Next

End Select

EndCode:
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.Display

End Sub
 

Forum Admin

Senior Member
The signature problem is easy - it's related to how the signature feature works. The signature is applied by a style and when there is no signature style, changing accounts won't add the signatue back.




I'm not sure why it lost the style on the original signature. Is that the complete code?
 

mystik

Member
Outlook version
Email Account
POP3
All of the accounts do have a signature. Yes, that is the complete code.
 

larry

Senior Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
But when you run the code, the signature style is removed and that is how the signature is changed.
 

mystik

Member
Outlook version
Email Account
POP3
No, when the code executes, the signature is not removed. The account is changed properly, but the signature does not change to that of the new account. It remains the default account signature.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Right click on the signature - which menu do you see?

If the signature menu, then the process does not kick off the style change.

If you see the standard content menu, the style is removed or not used when the message is opened using code.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That means the code that makes the signature switching feature work is not used (or is removed) by your procedure.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I checked with a coding experts and he says you need to simulate a click on the accounts button - just changing the account isn't enough. Not sure this will help here since the menu you see is not the correct one for signatures.
 

mystik

Member
Outlook version
Email Account
POP3
That is very discouraging. I don't know what I can do to get it going. :/
 

mystik

Member
Outlook version
Email Account
POP3
Slipstick, much appreciated for replying. Your site is where I found part of the original code. Thanks! :D

I removed the select case and just had it switch to one of them. It still does not change the signature for me. Any help you can offer would be massively appreciated. Thanks once again.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I realized it was based on that code after helping someone who wantted to always reply using a DL. :)




Testing it with the code tweaked to reply with a dl, the signature menu is available... the signature doesn't change (because its a DL and doesn't have an account or a sihnature assigned) - but i can change it. So something in your code is causing the signature feature to break. I just don't know what.










Public Sub New_Mail2()


Dim oAccount As Outlook.Account


Dim oMail As Outlook.MailItem


For Each oAccount In Application.Session.Accounts
If oAccount = "me@slipstick.com" Then
Set oMail = Application.CreateItem(olMailItem)
oMail.SendUsingAccount = oAccount
oMail.SentOnBehalfOfName = "emo@slipstick.com"
oMail.Display
End If


Next


End Sub




--------------------------------


Public Sub New_Reply()


Dim oAccount As Outlook.Account


Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
If oAccount = "me@slipstick.com" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.SentOnBehalfOfName = "emo@slipstick.com"
oMail.Display
End If
Next


End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
one more thing (from my macro expert), did you try switching display above the account change?




oMail.Display


oMail.SendUsingAccount = oAccount




(If that doesnt work, he's out of ideas)
 

mystik

Member
Outlook version
Email Account
POP3
Hate that I was not able to reply on this sooner (because I really appreciate any help). Something came up on this side. In any case, I tried this:

Public Sub New_Reply2()

Dim oAccount As Outlook.Account

Dim oMail As Outlook.MailItem

For Each oAccount In Application.Session.Accounts
If oAccount = "Algadon Support" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.Display
oMail.SendUsingAccount = oAccount
End If

Next

End Sub

and...

Public Sub New_Reply2()

Dim oAccount As Outlook.Account

Dim oMail As Outlook.MailItem

For Each oAccount In Application.Session.Accounts
If oAccount = "Algadon Support" Then
Set oMail = Application.ActiveExplorer.Selection(1).Reply
oMail.SendUsingAccount = oAccount
oMail.Display
End If

Next

End Sub

The account does not change with .SendUsingAccount = oAccount after .Display. With the other code, the signature can be changed by right click, though. Not sure what's the difference there, but sadly, the signature still does not change automatically. Is there somehow to actually change the signature by code, perhaps? Maybe that would be the way to go (if it is even possible). Worth a try anyway.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T Changing default Mail Account in Outlook 2016 - POP3 Using Outlook 1
V Outlook 2021 Can anyone explain why my Outlook views keep changing?! Using Outlook 2
P Outlook tasks keeps changing (updating) dates that I type Using Outlook 2
T Changing Sent Items location in Outlook 2019 Using Outlook 0
E Outlook view grouping keeps changing Using Outlook 3
J Outlook 2010 Changing events in Outlook calendar via opening file, importing CSV Using Outlook 0
T Outlook Contacts ... Changing Font Size, Style, Bold, etc. Using Outlook 2
M Outlook 2016: Changing default font for Notes and Reading Pane Using Outlook 4
Gary Hile Outlook 2016 changing editor options Using Outlook 6
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0
S Problems syncing emails with webmail after changing to Outlook 2016 Using Outlook 1
S Changing notification sound for new incoming messages in Outlook 365/2016 Using Outlook 1
D Outlook 2013 changing iCloud reminder time? Using Outlook 0
C Changing the name of Outlook Messages saved to a folder Using Outlook 1
A Outlook.com changing appointments Using Outlook 8
Diane Poremsky Changing Outlook.com color schemes Using Outlook 0
R Outlook calendar appointments Free/Busy time is changing from "Busy" to "Free" Using Outlook 2
W Changing looks of emails in Outlook 2003 Using Outlook 0
L Office 365 Outlook changing default contact folder Using Outlook 0
N Creating or changing the main new mail message template in Outlook 2010 Using Outlook 2
William Yeack Outlook/Exchange - Changing display of “From” user Using Outlook 3
S Outlook custom checkbox not changing value Using Outlook 0
B Problemss when changing from pop3 to imap email accounts in Outlook 2007 Using Outlook 2
P Changing all email signatures (font, color) at once in outlook 2007 Using Outlook 2
C Changing font sizes in Outlook 2013 Using Outlook 0
M Outlook 2012 Calendar Changing Secondary Calendar to Primary Calendar Using Outlook 1
X Outlook 2007+ Changing signature also changes subject? Using Outlook 9
C Outlook Changing Sent Message Headings to SPAM =?UTF-8?B?4Liq4Lij4LmJ4L Using Outlook 1
A Changing Tabs in Outlook 2010 Using Outlook 1
J Changing Colors or Font Styles on the Outlook Bar Using Outlook 1
J Move PST /changing default location in Outlook 2007 or 2010 64b on W7 64bit Using Outlook 2
V Changing Outlook settings Using Outlook 0
Y Changing colour of selection bar in Outlook (too light, needs to be grey) Using Outlook 4
K Outlook 2010 'cannot send on behalf of' when changing calendar apointment Exchange Server Administration 0
H Changing the default form in Outlook results in plain text Using Outlook 5
F Outlook 2010 - Default font color keeps changing frim the one I set. Using Outlook 1
O Changing meeting organizer in outlook Using Outlook 3
R Outlook-Changing default reply format to HTML Outlook VBA and Custom Forms 5
R Changing the default message form in Outlook 2007 Outlook VBA and Custom Forms 1
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 3
S Changing Message Class Outlook VBA and Custom Forms 4
C Pop Server Changing Verizon/Aol to Yahoo Using Outlook 6
e_a_g_l_e_p_i Changing where data .pst is saved to Using Outlook 3
P Changing the font that the task view shows Using Outlook 5
S Changing colors of today's appointments, but not recurring ones Using Outlook 33
B BCC issues after changing root folder path for gmail Using Outlook 1
M Changing the preferred order for "Put this entry in" list for adding new contacts to the Address Book Using Outlook 1
A .restrict results changing after moving to Exchange online Outlook VBA and Custom Forms 0
N Rule for "on behalf of" - with changing names Using Outlook 2
O Save attachments using hotkey without changing attributes Outlook VBA and Custom Forms 1

Similar threads

Top