A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Question abt Outlook 2003 VBA application by Sue Mosher*10152008



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 15th 08, 05:56 PM posted to microsoft.public.outlook.program_vba
J.Alladien
external usenet poster
 
Posts: 1
Default Question abt Outlook 2003 VBA application by Sue Mosher*10152008

Hello everybody,

I got the following code to automatically add recepients to contacts when
sending messages out to them:

' sample Outlook 2003 VBA application by Sue Mosher
' send questions/comments to

' 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

I inserted the first part which is:

' sample Outlook 2003 VBA application by Sue Mosher
' send questions/comments to

' 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

into "THIS OUTLOOK SESSION" and the rest of the code in"MODULE1",but when I
reply to a message the recepient doesn't get added!

As I am more experienced in MS Access I know that you have to somehow
"trigger" these codes to work properly ,can somebody advise me if I am on the
right track,and if not supply me with the steps to come on the right track!

BUT I HAVE ANOTHER IMPORTANT QUESTION:
**WILL THIS AUTOADD_CODE WORK WITH AUTOREPLIES??**

Cause I tried it in Outlook express and there It did not work,it only worked
when I "manually" replied!


Thanks in advance
Ads
  #2  
Old October 15th 08, 07:42 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Question abt Outlook 2003 VBA application by Sue Mosher*10152008

Please see my response on your original thread at
http://www.microsoft.com/communities...3-6e45b4a4454e
.. You don't need to start the conversation over in another newsgroup.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54




"J.Alladien" wrote:

Hello everybody,

I got the following code to automatically add recepients to contacts when
sending messages out to them:

' sample Outlook 2003 VBA application by Sue Mosher
' send questions/comments to

' 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

I inserted the first part which is:

' sample Outlook 2003 VBA application by Sue Mosher
' send questions/comments to

' 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

into "THIS OUTLOOK SESSION" and the rest of the code in"MODULE1",but when I
reply to a message the recepient doesn't get added!

As I am more experienced in MS Access I know that you have to somehow
"trigger" these codes to work properly ,can somebody advise me if I am on the
right track,and if not supply me with the steps to come on the right track!

BUT I HAVE ANOTHER IMPORTANT QUESTION:
**WILL THIS AUTOADD_CODE WORK WITH AUTOREPLIES??**

Cause I tried it in Outlook express and there It did not work,it only worked
when I "manually" replied!


Thanks in advance

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot send outlook 2003 email from other application Beemer Outlook - General Queries 0 May 6th 07 09:21 AM
TO : Sue Mosher [MVP-Outlook] Edward Outlook - General Queries 1 January 12th 07 05:09 AM
Suggestions from an Outlook 2003 Application Developer JuneBug Outlook - Calandaring 3 October 3rd 06 10:26 PM
Integration of Java application with Microsoft Outlook 2003 mulayarvind Outlook - General Queries 1 September 8th 06 01:28 PM
Slipstick Question for Sue Mosher MVP Jack Barrett Outlook - General Queries 1 February 4th 06 06:11 PM


All times are GMT +1. The time now is 09:06 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.