Apply Photo to Contact

  • Thread starter Thread starter Programatix
  • Start date Start date
Outlook 2003? Use the ContactItem.HasPicture Boolean to see if a picture is
there for the contact. Use the AddPicture(path) method to add a picture to
the contact.

For earlier versions of Outlook you'd need to add a custom control such as a
picturebox to add a picture.
 
Thanks for the quick respond.

While waiting for the respond from the newsgroup, I did some research using
the Office Help and come out with the following code to add photo for each
contacts. The image file should be named like the contact's name.

Hope it is useful to anyone out there.

Public Sub UpdateContactPhoto(ContactPhotoPath As String)
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.GetDefaultFolder(olFolderContacts).Items

Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
For Each myItem In myContacts
If (myItem.Class = olContact) Then
Dim myContact As Outlook.ContactItem
Set myContact = myItem

Dim strPhoto As String
strPhoto = ContactPhotoPath & myContact.FileAs & ".jpg"
If fs.FileExists(strPhoto) Then
myContact.AddPicture strPhoto
myContact.Save
End If
End If
Next
End Sub
 
Back
Top