View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default help with email from excel

Your second procedure appears to do what you ask. It should send an email
only the first time it finds a particular address in Column F that has the 5
in column G. Unless you store the dictionary in a public variable, it
should be empty each time you run the macro and have no memory of previous
emails sent.

--
Regards,
Tom Ogilvy

"Lobo" wrote in message
...
Yesterday, i was given help with my code. I have a spreadsheet with many

rows, each row representing a task. Each row has a person in its column.
When a task comes due (when days left = 5), I want the spreadsheet to email
the person involved. Now my problem is that one person may have about 20
tasks to do in one day. I dont want them to receieve 20 emails. I just
want them to receive one per day regardless of the number of tasks they have
due that day. For example, 5 things due march 2nd so it sends one email and
then detects that it has sent one and doesnt anymore. Then on march 3rd I
run the macro and the person has 7 tasks due and it sends the person another
email reminding him that he has tasks due in 5 days. Any ideas on how i
could do this?

I started with ron de bruin's code
--------------------------------------------
Sub TestFile2()
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim cell As Range
Application.ScreenUpdating = False
Set olApp = New Outlook.Application
For Each cell In

Sheets("Sheet1").Columns("B").Cells.SpecialCells(x lCellTypeConstants)
If cell.Offset(0, 1).Value < "" Then
If cell.Value Like "*@*" And cell.Offset(0, 1).Value = "yes"

Then
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & cell.Offset(0, -1).Value & vbNewLine

& vbNewLine & _
"Please contact us to discuss bringing your

account up to date"
.Send 'Or use Display
End With
Set olMail = Nothing
End If
End If
Next cell
Set olApp = Nothing
Application.ScreenUpdating = True
End Sub
--------------------------------------------
Then I got help yesterday but I dont think this code below works as I

wanted it to... It doesnt let me email the person ever again after doing it
once (and i dont think it sent me an email to begin with when i tested it at
all...)

--------------------------------------------
Sub SendEmailRoutine()
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim cell As Range
Dim addresslist As Scripting.Dictionary ' NEW
Dim sAddress As String 'NEW
Set addresslist = New Scripting.Dictionary 'NEW


Application.ScreenUpdating = False
Set olApp = New Outlook.Application
For Each cell In

Sheets("Sheet1").Columns("F").Cells.SpecialCells(x lCellTypeConstants)
sAddress = cell.Value
If cell.Offset(0, 1).Value < "" Then

If sAddress Like "*" And cell.Offset(0, 1).Value = "5" Then '

CHANGE
addresslist.Add sAddress, sAddress 'NEW

If Not addresslist.Exists(sAddress) Then 'NEW
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & cell.Value & vbNewLine &

vbNewLine & _
"You have an action due in 5 days! Please

contact us."
.Send 'Or use Display
End With
Set olMail = Nothing
End If

End If ' NEW

End If
Next cell
Set olApp = Nothing
Application.ScreenUpdating = True
End Sub
--------------------------------------------


Are there any other methods I could use to approach this problem?
Any help would be greatly appreciated

Thanks,
Lobo