Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OUTLOOK 2003 VBA DOESN'T AUTO RUN

Status
Not open for further replies.

Evil8

MIS
Mar 3, 2006
313
US
Running Office 2003 on WinXP SP3.

I have this VBA, it runs without error, but only manually. I want it run automaticaly when Outlook 2003 is started every time a Contact is changed. Maybe I stuck it in the wrong place? In the Microsoft Visual Basic Editor I have:
Project 1
-Microsoft Office Outlook Objects
-ThisOutlookSession

myContacts ItemChange

Public WithEvents myContacts As Items

Public Sub Initialize_myContacts()
Set myContacts = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items

End Sub

Private Sub myContacts_ItemChange(ByVal Item As Object)

Dim ContactUpdateMessage As MailItem

If MsgBox("Notify the office of this contact change?", vbYesNo + vbQuestion, "Contact Data Changed") = vbYes Then
Set ContactUpdateMessage = Application.CreateItem(ItemType:=olMailItem)
With ContactUpdateMessage
.To = "Office"
.Subject = "Contact Detail Change: " & Item.Subject
.Body = "The following contact has changed: " & vbCr & cbCr & Item.Subject
.Attachments.Add Source:=Item, Position:=50
.Send
End With
End If

End Sub


Also when I tested it, I used my email address in the .To line. As I said it ran without error, Clicking the Save and Close button creates a duplicate entry in My Contacts instead of overwriting the original. Does anyone know why that happens?

Thank you for your time.
Evil8
 
Okay for anyone interested I found the fix:

I needed to run the Initialize_myContacts procedure automatically when Outlook starts by using the Application_Startup event handler in the drop-down object and method lists at the top of the code window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top