Welcome to Lockergnome.com!
HomeHome FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log in/Register/PasswordLog in/Register/Password

Creating message if Contact's birthday is today

 
   Home -> Office -> Programming VBA RSS
Next:  Programming VBA: Set all Task fields from Subject Line  
Author Message
devstuff

External


Since: Aug 07, 2007
Posts: 1



(Msg. 1) Posted: Tue Aug 07, 2007 11:13 am
Post subject: Creating message if Contact's birthday is today
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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
Back to top
Login to vote
Michael Bauer [MVP - Outl

External


Since: Aug 04, 2006
Posts: 594



(Msg. 2) Posted: Wed Aug 08, 2007 2:19 am
Post subject: Re: Creating message if Contact's birthday is today [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

WScript is unknown. Replace WSCript.Echo by MsgBox.

It the code runs within Outlook then delete the Set ol = New ... line, and
replace ol.GetNameSpace by Application.GetNamespace.

You do not set any date to the today variable, so the value is 0. The Date
function would return the current date.

If you want one message be displayed if there's no birthday today at all
then use another variable declared As Boolean. If one birthday is found then
set it = True. Eventually, if the variable is still False (inital value)
then you know that it never was set to True, i.e. no birthday.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize eMails:
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6>

Am Tue, 07 Aug 2007 11:13:01 -0700 schrieb devstuff.RemoveThis@gmail.com:

> 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
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 General
 Microsoft Windows XP
 Microsoft Windows Vista
 Microsoft Windows (other)
  Microsoft Office
 Microsoft Office (other)
 Computer Security
 Linux
 Movies


[ Contact us | Terms of Service/Privacy Policy ]