Change FROM address based on TO or CC address

Status
Not open for further replies.

whizzard

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
Hi All,

I'm seeking assistance with the VBA code to change the FROM address when replying to or forwarding an email based on the address in the TO or CC of the original email.

Why?
User A has a mailbox that is shared with User B.
User B is charged with sending, replying and forwarding User A's email as User A.
The messages are BCC'd to User B, as User A don't want the message marked as read before he/she reads them.

User B has Send As permission for User A. I'm trying to have it where when User B is performing a task with an email addressed to User A, Outlook automatically changes the FROM address to User A's address so User A doesn't have to remember to change it.

Is this possible? If so I'll appreciate any assistance given.

Thank you.
 
I see you found the link I was looking for - yes, it can be tweaked.

and this one -

The quickie explanation -

' Check the message for users address in the recipients -

For Each Recipient In oItem.Recipients
strRecip = Recipient.Address & ";" & strRecip
Next Recipient

'check the list for the addresses
If InStr(strRecip, "userA@address") > 0 Then

' use this as the reply address.
objnewmessage.SentOnBehalfOfName = "sales@domain.com"

End If

(I'm on my Mac laptop right now and can't test a macro. But yes, it is doable.)
 
Thanks very much Diane. Will anything need to be changed for Outlook 2016/2019?

I've tried to follow from the links provided as well as Reply using the address a message was sent to but mainly the Gmail one, yet Outlook seems to ignore the macro and still sends only from the default.
 
It will work in all versions of Outlook.

yet Outlook seems to ignore the macro and still sends only from the default.
Assuming the macro security is allowing it...

In the VBA editor, in Tools > Options> General - set it to break on all errors. also, at the top of the macro, add
msgbox "It's working!!" - if that doesn't come up when the macro is called, its not working.

1657800008512.png
 
It will work in all versions of Outlook.


Assuming the macro security is allowing it...

In the VBA editor, in Tools > Options> General - set it to break on all errors. also, at the top of the macro, add
msgbox "It's working!!" - if that doesn't come up when the macro is called, its not working.

View attachment 3645
Still nothing. When I click Run I get a macros pop up.
VBA.PNG
 
The auto macros - which are anything that have something in the parens, like this: sub macroname(items as object)
will not be listed in the macro dialog. They are run by other processes.
 
Hi again,

I returned to the Gmail one to try debugging it. Once I restart Outlook, I get the error:

VBA 2.PNG


and it highlights this line "Set oItem = oExpl.Selection.Item(1)" in the oExpl_SelectionChange() sub.
 
Nothing looks out of the ordinary -and its a weird error. I'll need to test it in the morning.
 
Hi Diane,
I don't want to be a bother, but were you able to check out the error?
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Outlook Automatically Change "From" address based on "To" address Using Outlook 4
O What would be the recommended way to change an email address (family member)? Using Outlook 0
B Change from Address Outlook VBA and Custom Forms 0
S Example VBA Macro - To Conditionally Change the From Account and Add a BCC Address on Emails Outlook VBA and Custom Forms 11
B Do not change the From address in Outlook Templates Using Outlook 0
C Change From address while sending a new mail Outlook VBA and Custom Forms 5
B Change default email for address book Using Outlook 1
Maybear Sudden change in Outlook, no image display, email no longer offers suggestions for address Using Outlook 8
P Change the Outlook.com "from" address for calendar event invites Using Outlook 9
D Change To address when it is sent to a specific address during specfic time. Using Outlook 2
K Automatically Change "From" Address When Replying As An Alias? Using Outlook 5
R Change Outlook 2010 Exchange server address via registry or script Using Outlook 5
M Use Macro to change account settings Outlook VBA and Custom Forms 0
D Unable to change AppointmentItem.Start property Outlook VBA and Custom Forms 4
sjmo2 Change subject for new e-mails only. Outlook VBA and Custom Forms 2
Horsepower Contact phone numbers randomly change Using Outlook 0
P Outlook 2016 Change Paste Special Default Format Using Outlook 8
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
S Unable to change Message Class Outlook VBA and Custom Forms 0
S New Outlook Appointment - Select All Body Text and Change Font and Size Outlook VBA and Custom Forms 1
J VBA Cannot programmatically input or change Value for User Defined field Using Outlook 1
C Outlook 365 Can you change the follow up colour? Using Outlook 1
A Change settings Send/receive VBA Outlook VBA and Custom Forms 0
E Outlook VBA change GetDefaultFolder dynamically Outlook VBA and Custom Forms 6
S Change "This Week" flag start date behavior Using Outlook 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
D Change Microsoft Account password - what to do to update on all devices Using Outlook 4
S Outlook 2016 Change how Outlook shows me contacts in emails Using Outlook 0
Witzker HowTo Change message Class of contact form Outlook VBA and Custom Forms 0
Z Outlook 365 delete reminder you can’t make change to contents of this-read only folder Using Outlook 4
Witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
R How to Change Margins In Google Docs...? Using Outlook 0
e_a_g_l_e_p_i Outlook 2010 How can I change the font size on right side appointment pane Using Outlook 12
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
D Change senders title Using Outlook 1
W Recurrence: delete older occurrences / change earliest start time Outlook VBA and Custom Forms 0
E Change sending account depending on Subjectline Outlook VBA and Custom Forms 0
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 10
B Change row background color of selected item Using Outlook 1
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
X If you change expiration date of repeated task it dupplicates Using Outlook 1
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
Z See "Change View" Drop Down as a List? Using Outlook 1
V Change start time based on message duration Outlook VBA and Custom Forms 2
R Folder pane width change Using Outlook 90
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
S Outlook 2010 unable to change default font Using Outlook 7
P How can I change my calendar view back Using Outlook 3

Similar threads

Back
Top