Question abt Outlook 2003 VBA application by Sue Mosher*10152008

J

J.Alladien

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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!

Thanks in advance
 
S

Sue Mosher [MVP-Outlook]

Also, 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/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
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 said:
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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!

Thanks in advance
 
S

Sue Mosher [MVP-Outlook]

Does other Outlook VBA code run? You might want to start with the basics at
http://outlookcode.com/article.aspx?id=49
--
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 said:
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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!

Thanks in advance
 
J

J.Alladien

Thanks for your reply Sue,

You didn't mention anything abt the procedure I took, can I assume that I
did it correctly or not?
I will also post the same question in microsoft.public.outlook.program_vba !

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!


Sue Mosher said:
Also, 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/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
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 said:
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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!

Thanks in advance
 
S

Sue Mosher [MVP-Outlook]

Did you try what I suggested?

I don't understand your latest question. Outlook VBA code has nothing to do
with Outlook Express.
--
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 said:
Thanks for your reply Sue,

You didn't mention anything abt the procedure I took, can I assume that I
did it correctly or not?
I will also post the same question in microsoft.public.outlook.program_vba !

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!


Sue Mosher said:
Also, 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/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
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 said:
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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!
 
J

J.Alladien

Hi Sue,

Sorry ,I thought you suggested I needed to repost my thread in
the"programming" section!

I tried the basic "hello world" and it worked!

Will the " addauto code " also work on autoreplies?

Thanks



Sue Mosher said:
Did you try what I suggested?

I don't understand your latest question. Outlook VBA code has nothing to do
with Outlook Express.
--
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 said:
Thanks for your reply Sue,

You didn't mention anything abt the procedure I took, can I assume that I
did it correctly or not?
I will also post the same question in microsoft.public.outlook.program_vba !

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!


Sue Mosher said:
Also, 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/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54




:

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 (e-mail address removed)

' 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 (e-mail address removed)

' 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top