Send email using VBA from specific account

lionelnz

Well-known Member
Joined
Apr 6, 2006
Messages
571
Hi all.

I have searched the net high & low as well as the forum for code that will allow me to choose the email account to send my email from.

I have an XL dtatbase for applying for jobs and I use a specific email account when sending my job application emails to employers.

I have excellent code that allows me to save the the email as a draft and then I select the appropriate account.

I would like to select the account with VBA from XL.

I am using MSO 2002.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Thanks Andrew.

I have found this code from Sue Mosher at http://www.outlookcode.com/codedetail.aspx?id=889 but I am not too sure exactly how to use it with my code.

Do I call the function from my code or do I run the function first?

Code:
Function Set_Account(ByVal AccountName As String, M As Outlook.MailItem) As String
Dim OLI As Outlook.Inspector
Dim strAccountBtnName As String
Dim intLoc As Integer
Const ID_ACCOUNTS = 31224
Dim CBs As Office.CommandBars
Dim CBP As Office.CommandBarPopup
Dim MC As Office.CommandBarControl
Set OLI = M.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, ID_ACCOUNTS)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
End If
End If
Set_Account = ""
Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
End Function
 
Upvote 0
>I'm not sure that it's possible prior to Outlook 2007:

You can use this

Change sender name and reply address

If you want to change the sender name and reply address add this code line

'The receiver can see the original mail address in the properties if he want
.SentOnBehalfOfName = """SenderName"" <Reply@Address.com>"
 
Upvote 0
THanks Ron. I tried your code and it did not send from the right account. Lets say my general account is called Me@ISP.com and my other acount is MyJobs@ISP.com. What I want is for my code to send from MyJobs@ISP.com and not Me@ISP.com with a request to reply to MyJobs@ISP.com. :(

I want to keep my general account separate from my job account.

I can save a draft email using your original code Ron & then manually select the MyJobs@ISP.com account. Surely there must be away to select the account using VBA.

 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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