Make Excel send an email via VBA

J

Jens Lenge

How can I send an email from an Excel VBA macro?
I'd like to read a couple of email addresses from worksheet cells and have
VBA send an email with a specified text to each of them using a specified
SMTP mail account.

How can I do this?
Which mail command can I use?

Cheers, Jens
 
R

Rafael

Jens,

In case the examples on the site provided does not help, I just pieced
together a script that will accomplish what you're looking to do (I think)
since I ran into the same situation. See below and make adjustments as
needed.

Sub Send_Row()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim cell As Range
Dim rng As Range
Dim Ash As Worksheet
Dim wrd As Word.Application

'Open the word Document and use it's content for the body of the email -
use your own name here
Set wrd = GetObject(, "Word.Application")
wrd.Visible = True
wrd.Documents.Open ("C:\myDoc.doc")
Set myRange = wrd.Documents("myDoc.doc").Content

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
'get the list of emails from the rage and email everyone

For Each cell In Range("email") 'Use your own range name.
If cell.Value Like "*@*" Then
myName = cell.Offset(0, -3).Value ' if you want to address it to the
person's name, indicate how many columns to the left the name appears on
'myArray = Split(myName, " ", -1, 1) ' if you want to address the email
to "John" instead of John Doe, just use this split function
'myName = myArray(0)
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = cell.Value
.Subject = "Subject goes here"
.HTMLBody = myName & "," & "<p>" & myRange
.Display
End With
End If
Next cell

Set OutApp = Nothing
Set myRange = Nothing
Set myArray = Nothing

End Sub

I'm not doing any error checking ;).

Rafael
 
J

Jens Lenge

Rafael,

thank you for your Script.
It's nice to have more than one choice.
I will try it.

Cheers, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top