View Single Post
  #4   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

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
on Error Resume Next
addresslist.Add sAddress, sAddress 'NEW
if err.Number = 0 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
Else
err.clear
End If
On error goto 0
End If ' NEW

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

Untested

--
Regards,
Tom Ogilvy



"Lobo" wrote in message
...
Hey Tom,

I'm currently working with a miniature spreadsheet that loosk just like

this below:

F G
Name Days Left
Terrel Lobo 5
Terrel Lobo 15
Steve Lobo 14
Terrel Lobo 5
Karen Lobo 5
Terrel Lobo 5

When i run the macro with the second code, I get "This key is already

associated with an element of this collection" and no emails are sent to
myself or karen.

If i change the spreadsheet to:

Name Days Left
Terrel Lobo 5
Terrel Lobo 15
Steve Lobo 14
Terrel Lobo 10
Karen Lobo 10
Terrel Lobo 10

and then run the macro, absolutely nothing happens. No email gets sent to

Terrel Lobo.

I have no idea what to do to solve this. However if i use the basic code

on ron de bruin's site, it sends the email out.

Any ideas tom?