VBA email signature from secondary account

dotsent

Board Regular
Joined
Feb 28, 2016
Messages
85
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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

Forum statistics

Threads
1,214,793
Messages
6,121,619
Members
449,039
Latest member
Mbone Mathonsi

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