Thread: Send Email
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Send Email

Hi Allan,

This hasn't been tested because I don't use Outlook, but it should be close
to what you want. It handles the worksheet and passes the email address in
columnG to Mail() if the date in columnB is 14 days or older than the current
date.

Modify to suit...

'Put this in the code behind the worksheet
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Set rng = Intersect(Target, Range("X:X"))

If Not rng Is Nothing Then
If Target.Value = "No" And _
Cells(Target.Row, "B") <= (Date - 14) Then _
Mail Cells(Target.Row, "G")
End If

End Sub

'Modify as follows
Sub Mail(strto As String)
Dim OutApp As Object
Dim OutMail As Object
Dim strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strcc = ""
strbcc = ""
strsub = "Important message"
strbody = "Hi there" & vbNewLine & vbNewLine & _
"Cell A1 is changed"
With OutMail
.To = strto
.cc = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Regards,
GS