Add the code below to your ThisOutlookSession module. It should meet your
needs; tweak it if it doesn't!
You don't have to use a custom button for this sample. It'll send the
Contact as an attachment to a new e-mail message upon close, if it detects
that the Contact was saved.
Note that Outlook versions greater than 2000 or with the E-mail Security
Update will get prompted to send the message. See
http://www.slipstick.com/outlook/esecup.htm#autosec for more info.
Also, be careful about how many newsgroups you cross-post to. There's
usually only one or two groups max that is applicable to any given question.
Option Explicit
Dim WithEvents objInspectors As Inspectors
Dim WithEvents objContactItem As Outlook.ContactItem
Dim blnContactChanged As Boolean
Private Sub Application_Startup()
Set objInspectors = Application.Inspectors
End Sub
Private Sub Application_Quit()
Set objInspectors = Nothing
Set objContactInspector = Nothing
End Sub
Private Sub objContactItem_Close(Cancel As Boolean)
If blnContactChanged Then
SendEmailWithUpdatedContact
End If
blnContactChanged = False
End Sub
Private Sub objContactItem_Write(Cancel As Boolean)
blnContactChanged = True
End Sub
Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class <> olContact Then Exit Sub
Set objContactItem = Inspector.CurrentItem
End Sub
Sub SendEmailWithUpdatedContact()
Dim objMailItem As Outlook.MailItem
Set objMailItem = Application.CreateItem(olMailItem)
objMailItem.Attachments.Add objContactItem, olByValue
objMailItem.Subject = "Updated contact"
objMailItem.To = "(e-mail address removed)"
objMailItem.Send
End Sub