Hi, everybody,
I'm facing a problem with the hereunder code.
What I'm trying to achieve is:
a) I would like the code to browse my contacts an find those that celebrate their Birthday, - today.
b) Please note the two command which provide a "run-time error 424" if one, or more, recipient(s) Birthdays fall within today.
* Where did I go wrong and what can be done to correct it ? *
Thanks, Elm
I'm facing a problem with the hereunder code.
What I'm trying to achieve is:
a) I would like the code to browse my contacts an find those that celebrate their Birthday, - today.
b) Please note the two command which provide a "run-time error 424" if one, or more, recipient(s) Birthdays fall within today.
* Where did I go wrong and what can be done to correct it ? *
Thanks, Elm
Code:
Sub GetTodaysContactsBirthdays()
Dim olns As Outlook.NameSpace
Dim oConItems As Outlook.Items
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set oConItems = olns.GetDefaultFolder(olFolderContacts).Items
Flag = 0
For Each ocuritem In oConItems
If ocuritem.Class = 40 Then ' 40=olcontact
If ocuritem.Birthday = Date Then
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Happy Birthday"
msg.Address = ocuritem.Email1Address ''' run- time error 424
msg.Address = objContactItem.Email1Address ''' run- time error 424
msg.Display
Set msg = Nothing
Flag = Flag + 1
End If
'Else
' Not an individual contact, no Birthday property
End If
Next
If Flag = 0 Then MsgBox "No Birthdays Today"
End Sub
Last edited: