Export Excel Data to an Outlook Email

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Sounds simple but this is proving a headache for me. I'm looking for any
smnippest of code out there that can handle the following.

In column A I have the date an email should be sent.
In Column B I have the email address to which the email is to be sent.
In Column C I have the subject of the email
In Column D I have the body of the email.
In Column E I have the name of the person sending the email.

The code I'm looking for needs to work like this.

If I click on any cell in column A (on any date), nothing must happen,
unless the date is 'today'. If the datre is today this will trigger the data
in columns b,c,d,e to be entered into an email launched from Outlook in the
roder highlighted below.

If there are any clever boffins out there please help me...

Gordon
 
Thanks for that...

Have you got a working example of this code...

Gordon
 
Hi Gordon

Try this, use display in the code to test

'In column A I have the date an email should be sent.
'In Column B I have the email address to which the email is to be sent.
'In Column C I have the subject of the email
'In Column D I have the body of the email.
'In Column E I have the name of the person sending the email.
'In column F copy down this formula
=IF(A1= TODAY(),"Yes","No")


Sub TestFile()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" And LCase(cell.Offset(0, 4).Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.Subject = cell.Offset(0, 1).Value
.Body = cell.Offset(0, 2).Value
.Send 'Or use Display
End With
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
 
Thanks Ron...

Ron de Bruin said:
Hi Gordon

Try this, use display in the code to test

'In column A I have the date an email should be sent.
'In Column B I have the email address to which the email is to be sent.
'In Column C I have the subject of the email
'In Column D I have the body of the email.
'In Column E I have the name of the person sending the email.
'In column F copy down this formula
=IF(A1= TODAY(),"Yes","No")


Sub TestFile()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Sheets("Sheet1").Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" And LCase(cell.Offset(0, 4).Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.Subject = cell.Offset(0, 1).Value
.Body = cell.Offset(0, 2).Value
.Send 'Or use Display
End With
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
 

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

Back
Top