VBA email signature from secondary account

dotsent

Board Regular
Joined
Feb 28, 2016
Messages
89
Office Version
  1. 365
Platform
  1. Windows
I have a problem choosing the correct signature when sending mail from Excel via Outlook (Office365). I have 2 accounts set up in Outlook, one is primary email and the other is secondary email with both having different default signatures. Secondary email is a shared mailbox, but added as a separate account with full rights. The goal is to both send out and add the signature from the secondary account.

.Display opens up new mail item while adding Outlook's signature and .SentOnBehalfOfName even shows the secondary account in FROM panel (and also sends out the mail from that account), however Outlook still grabs the signature from primary email account.

In case I manually choose (or re-select) the secondary account from the mail message's FROM drop-down menu, Outlook will change the signature to the right one, however that's really not an option as I'm looking to automate this (uncomment .Send) and run this code in a loop for a few times in a row. I did try making the secondary address as the default address, however ran into additional problems and felt there should be a better way to handle this.

Any ideas please?

I have tried the option of linking to the AppData folder to grab the signature HTML file, however it does have a pic included which appears to be a problem.

Code:
Sub Email()
    
    Dim OutApp As Object
    Dim OutMail As Object
      
    On Error Resume Next
    
    On Error GoTo 0

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    
    With OutMail  
        
        .SentOnBehalfOfName = "secondary@email.com"
        .Display
        .To = "test@email.com"
        .CC = ""
        .BCC = ""
        .Subject = "mySubject"
        .HTMLBody = "[FONT=calibri][SIZE=3]mailBody text[/SIZE][/FONT]" & .HTMLBody
        '.Send
        
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello,

Sorry, I know this is a very old post but I have the exact same problem.. I was wondering if you have ever found a solution..

Cheers

I have a problem choosing the correct signature when sending mail from Excel via Outlook (Office365). I have 2 accounts set up in Outlook, one is primary email and the other is secondary email with both having different default signatures. Secondary email is a shared mailbox, but added as a separate account with full rights. The goal is to both send out and add the signature from the secondary account.

.Display opens up new mail item while adding Outlook's signature and .SentOnBehalfOfName even shows the secondary account in FROM panel (and also sends out the mail from that account), however Outlook still grabs the signature from primary email account.

In case I manually choose (or re-select) the secondary account from the mail message's FROM drop-down menu, Outlook will change the signature to the right one, however that's really not an option as I'm looking to automate this (uncomment .Send) and run this code in a loop for a few times in a row. I did try making the secondary address as the default address, however ran into additional problems and felt there should be a better way to handle this.

Any ideas please?

I have tried the option of linking to the AppData folder to grab the signature HTML file, however it does have a pic included which appears to be a problem.

Code:
Sub Email()
   
    Dim OutApp As Object
    Dim OutMail As Object
     
    On Error Resume Next
   
    On Error GoTo 0

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
   
    With OutMail 
       
        .SentOnBehalfOfName = "secondary@email.com"
        .Display
        .To = "test@email.com"
        .CC = ""
        .BCC = ""
        .Subject = "mySubject"
        .HTMLBody = "[FONT=calibri][SIZE=3]mailBody text[/SIZE][/FONT]" & .HTMLBody
        '.Send
       
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
   
End Sub
 
Upvote 0
Hi there, me too having the same problem. If one of you could help me, that would be very much appreciated.
 
Upvote 0
It works!! Thanks a lot
I'm having the same problem. Do you have the full code with the following in it. I'm having trouble getting it to work.
With objMail
Set .SendUsingAccount
 
Upvote 0
Does anyone have the full code for this? The accepted answer is incredibly ambiguous and I'm still not understanding. Any help is greatly appreciated!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top