using VBA to send Outlook emails

bluesocks

New Member
Joined
Jul 21, 2011
Messages
1
Hi all,

I've got the below code to generate an outlook email in VBA, how would I define what goes into the "From" field in the email?

Ta!

Code:
Sub SendEmail(address As String, Subject As String, Body As String)
     
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail

.From = "mailbox@me.com"
.To = address
.CC = ""
.BCC = "mailbox@me.com"
.Subject = Subject
.Body = Body

' .Attachments.Add ActiveWorkbook.FullName
' .Attachments.Add ("")
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
     
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You did specify the .Fom field, didn't you?
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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