PC Review


Reply
Thread Tools Rate Thread

Adding senders automatically to contact list

 
 
=?Utf-8?B?UGlldHJv?=
Guest
Posts: n/a
 
      24th Apr 2007
Hi all,

I'd like to add all the e-mails of those who send me messages
automatically to new contact list,i'm using the below code but unfortunately
it does not work.
Could anybody help?


' The Application_ItemSend procedure must go in the
' built-in ThisOutlookSession session module in Outlook VBA
Private Sub Application_ItemSend(ByVal Item As Object, _
Cancel As Boolean)
If Item.Class = olMail Then
Call AddRecipToContacts(Item)
End If
Set Item = Nothing
End Sub

' This procedure can go in any module
Sub AddRecipToContacts(objMail As Outlook.MailItem)
Dim strFind As String
Dim strAddress As String
Dim objNS As Outlook.NameSpace
Dim colContacts As Outlook.Items
Dim objContact As Outlook.ContactItem
Dim objRecip As Outlook.Recipient
Dim i As Integer
On Error Resume Next

' get Contacts folder and its Items collection
Set objNS = Application.GetNamespace("MAPI")
Set colContacts = _
objNS.GetDefaultFolder(olFolderContacts).Items

' process message recipients
For Each objRecip In objMail.Recipients
' check to see if the recip is already in Contacts
strAddress = AddQuote(objRecip.Address)
For i = 1 To 3
strFind = "[Email" & i & "Address] = " & _
strAddress
Set objContact = colContacts.Find(strFind)
If Not objContact Is Nothing Then
Exit For
End If
Next

' if not, add it
If objContact Is Nothing Then
Set objContact = _
Application.CreateItem(olContactItem)
With objContact
.FullName = objRecip.Name
.Email1Address = strAddress
.Save
End With
End If
Set objContact = Nothing
Next

Set objNS = Nothing
Set objContact = Nothing
Set colContacts = Nothing
End Sub

' helper function - put in any module
Function AddQuote(MyText) As String
AddQuote = Chr(34) & MyText & Chr(34)
End Function



 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      24th Apr 2007
Please be specific about what doesn't work. DOes any VBA code run at all? Have you added a breakpoint and stepped through the code?

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/comm...ok.program_vba


--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pietro" <(E-Mail Removed)> wrote in message news:8A694EC8-E8ED-405C-9BC5-(E-Mail Removed)...
> Hi all,
>
> I'd like to add all the e-mails of those who send me messages
> automatically to new contact list,i'm using the below code but unfortunately
> it does not work.
> Could anybody help?
>
>
> ' The Application_ItemSend procedure must go in the
> ' built-in ThisOutlookSession session module in Outlook VBA
> Private Sub Application_ItemSend(ByVal Item As Object, _
> Cancel As Boolean)
> If Item.Class = olMail Then
> Call AddRecipToContacts(Item)
> End If
> Set Item = Nothing
> End Sub
>
> ' This procedure can go in any module
> Sub AddRecipToContacts(objMail As Outlook.MailItem)
> Dim strFind As String
> Dim strAddress As String
> Dim objNS As Outlook.NameSpace
> Dim colContacts As Outlook.Items
> Dim objContact As Outlook.ContactItem
> Dim objRecip As Outlook.Recipient
> Dim i As Integer
> On Error Resume Next
>
> ' get Contacts folder and its Items collection
> Set objNS = Application.GetNamespace("MAPI")
> Set colContacts = _
> objNS.GetDefaultFolder(olFolderContacts).Items
>
> ' process message recipients
> For Each objRecip In objMail.Recipients
> ' check to see if the recip is already in Contacts
> strAddress = AddQuote(objRecip.Address)
> For i = 1 To 3
> strFind = "[Email" & i & "Address] = " & _
> strAddress
> Set objContact = colContacts.Find(strFind)
> If Not objContact Is Nothing Then
> Exit For
> End If
> Next
>
> ' if not, add it
> If objContact Is Nothing Then
> Set objContact = _
> Application.CreateItem(olContactItem)
> With objContact
> .FullName = objRecip.Name
> .Email1Address = strAddress
> .Save
> End With
> End If
> Set objContact = Nothing
> Next
>
> Set objNS = Nothing
> Set objContact = Nothing
> Set colContacts = Nothing
> End Sub
>
> ' helper function - put in any module
> Function AddQuote(MyText) As String
> AddQuote = Chr(34) & MyText & Chr(34)
> End Function
>
>
>

 
Reply With Quote
 
=?Utf-8?B?UGlldHJv?=
Guest
Posts: n/a
 
      24th Apr 2007
Thank you for your answer,
It does not work means that i receive messages and the senders are not
added automatically to the contacts,this is the first code i'm trying to run
on my Outlook,by the way i don't have good experience in Outlook programming

"Sue Mosher [MVP-Outlook]" wrote:

> Please be specific about what doesn't work. DOes any VBA code run at all? Have you added a breakpoint and stepped through the code?
>
> FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/comm...ok.program_vba
>
>
> --
> Sue Mosher, Outlook MVP
> Author of Configuring Microsoft Outlook 2003
> http://www.turtleflock.com/olconfig/index.htm
> and Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
> "Pietro" <(E-Mail Removed)> wrote in message news:8A694EC8-E8ED-405C-9BC5-(E-Mail Removed)...
> > Hi all,
> >
> > I'd like to add all the e-mails of those who send me messages
> > automatically to new contact list,i'm using the below code but unfortunately
> > it does not work.
> > Could anybody help?
> >
> >
> > ' The Application_ItemSend procedure must go in the
> > ' built-in ThisOutlookSession session module in Outlook VBA
> > Private Sub Application_ItemSend(ByVal Item As Object, _
> > Cancel As Boolean)
> > If Item.Class = olMail Then
> > Call AddRecipToContacts(Item)
> > End If
> > Set Item = Nothing
> > End Sub
> >
> > ' This procedure can go in any module
> > Sub AddRecipToContacts(objMail As Outlook.MailItem)
> > Dim strFind As String
> > Dim strAddress As String
> > Dim objNS As Outlook.NameSpace
> > Dim colContacts As Outlook.Items
> > Dim objContact As Outlook.ContactItem
> > Dim objRecip As Outlook.Recipient
> > Dim i As Integer
> > On Error Resume Next
> >
> > ' get Contacts folder and its Items collection
> > Set objNS = Application.GetNamespace("MAPI")
> > Set colContacts = _
> > objNS.GetDefaultFolder(olFolderContacts).Items
> >
> > ' process message recipients
> > For Each objRecip In objMail.Recipients
> > ' check to see if the recip is already in Contacts
> > strAddress = AddQuote(objRecip.Address)
> > For i = 1 To 3
> > strFind = "[Email" & i & "Address] = " & _
> > strAddress
> > Set objContact = colContacts.Find(strFind)
> > If Not objContact Is Nothing Then
> > Exit For
> > End If
> > Next
> >
> > ' if not, add it
> > If objContact Is Nothing Then
> > Set objContact = _
> > Application.CreateItem(olContactItem)
> > With objContact
> > .FullName = objRecip.Name
> > .Email1Address = strAddress
> > .Save
> > End With
> > End If
> > Set objContact = Nothing
> > Next
> >
> > Set objNS = Nothing
> > Set objContact = Nothing
> > Set colContacts = Nothing
> > End Sub
> >
> > ' helper function - put in any module
> > Function AddQuote(MyText) As String
> > AddQuote = Chr(34) & MyText & Chr(34)
> > End Function
> >
> >
> >

>

 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      24th Apr 2007
You should make sure you've taking care of the basics of running VBA code. See http://www.outlookcode.com/d/vbabasics.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pietro" <(E-Mail Removed)> wrote in message news:4FA080E0-847E-4677-95DE-(E-Mail Removed)...
>
> It does not work means that i receive messages and the senders are not
> added automatically to the contacts,this is the first code i'm trying to run
> on my Outlook,by the way i don't have good experience in Outlook programming
>
>> >
>> > I'd like to add all the e-mails of those who send me messages
>> > automatically to new contact list,i'm using the below code but unfortunately
>> > it does not work.
>> > Could anybody help?
>> >
>> >
>> > ' The Application_ItemSend procedure must go in the
>> > ' built-in ThisOutlookSession session module in Outlook VBA
>> > Private Sub Application_ItemSend(ByVal Item As Object, _
>> > Cancel As Boolean)
>> > If Item.Class = olMail Then
>> > Call AddRecipToContacts(Item)
>> > End If
>> > Set Item = Nothing
>> > End Sub
>> >
>> > ' This procedure can go in any module
>> > Sub AddRecipToContacts(objMail As Outlook.MailItem)
>> > Dim strFind As String
>> > Dim strAddress As String
>> > Dim objNS As Outlook.NameSpace
>> > Dim colContacts As Outlook.Items
>> > Dim objContact As Outlook.ContactItem
>> > Dim objRecip As Outlook.Recipient
>> > Dim i As Integer
>> > On Error Resume Next
>> >
>> > ' get Contacts folder and its Items collection
>> > Set objNS = Application.GetNamespace("MAPI")
>> > Set colContacts = _
>> > objNS.GetDefaultFolder(olFolderContacts).Items
>> >
>> > ' process message recipients
>> > For Each objRecip In objMail.Recipients
>> > ' check to see if the recip is already in Contacts
>> > strAddress = AddQuote(objRecip.Address)
>> > For i = 1 To 3
>> > strFind = "[Email" & i & "Address] = " & _
>> > strAddress
>> > Set objContact = colContacts.Find(strFind)
>> > If Not objContact Is Nothing Then
>> > Exit For
>> > End If
>> > Next
>> >
>> > ' if not, add it
>> > If objContact Is Nothing Then
>> > Set objContact = _
>> > Application.CreateItem(olContactItem)
>> > With objContact
>> > .FullName = objRecip.Name
>> > .Email1Address = strAddress
>> > .Save
>> > End With
>> > End If
>> > Set objContact = Nothing
>> > Next
>> >
>> > Set objNS = Nothing
>> > Set objContact = Nothing
>> > Set colContacts = Nothing
>> > End Sub
>> >
>> > ' helper function - put in any module
>> > Function AddQuote(MyText) As String
>> > AddQuote = Chr(34) & MyText & Chr(34)
>> > End Function
>> >
>> >
>> >

>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically adding senders email address to a distribution list? phil Microsoft Outlook Discussion 1 21st Jul 2009 11:35 AM
automatically delete messages from senders my junk senders list =?Utf-8?B?ZGVi?= Microsoft Outlook Discussion 2 24th Dec 2005 12:25 AM
automatically delete messages from senders my junk senders list =?Utf-8?B?ZGVi?= Microsoft Outlook Discussion 0 22nd Dec 2005 07:30 PM
Automatically delete after adding email to Junk Senders List? =?Utf-8?B?VW1hJ3MgQXVudA==?= Microsoft Outlook Discussion 1 27th Jul 2005 08:41 PM
Adding senders names to contact list =?Utf-8?B?TW4gU2xpbQ==?= Microsoft Outlook Contacts 3 30th Nov 2004 04:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 AM.