D
devstuff
I've put together a macro to scan a users contacts folder for any
contact who's birthday is today, and create a new message to send.
I'll eventually expand it to add custom messages (based on contacts
name) and auto send the email, but for now I'm trying to establish the
basic find and create. I'm running into an 'expected object' that I
believe is a problem with the date.
Also, the way the code is written, it seems like my 'No Birthdays
Today' message would be written for every contact who's birthday isn't
today, but it's the only way I could put it together so that the
debugger didn't say 'For with no Next' or 'Next with no For'.
Any help steering me towards funtionality would be greatly
appreciated.
Code's Below.
Thanks.
Sub getContacts()
Dim today As Date
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
For Each oCurItem In oConItems
If oCurItem.Birthday = today Then
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Happy Birthday"
msg.Address = objContactItem.Email1Address
msg.Display
Set msg = Nothing
Else
Wscript.Echo "No Birthdays Today"
End If
Next
End Sub
contact who's birthday is today, and create a new message to send.
I'll eventually expand it to add custom messages (based on contacts
name) and auto send the email, but for now I'm trying to establish the
basic find and create. I'm running into an 'expected object' that I
believe is a problem with the date.
Also, the way the code is written, it seems like my 'No Birthdays
Today' message would be written for every contact who's birthday isn't
today, but it's the only way I could put it together so that the
debugger didn't say 'For with no Next' or 'Next with no For'.
Any help steering me towards funtionality would be greatly
appreciated.
Code's Below.
Thanks.
Sub getContacts()
Dim today As Date
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
For Each oCurItem In oConItems
If oCurItem.Birthday = today Then
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = "Happy Birthday"
msg.Address = objContactItem.Email1Address
msg.Display
Set msg = Nothing
Else
Wscript.Echo "No Birthdays Today"
End If
Next
End Sub