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.
.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: