Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Apply Photo to Contact (http://www.outlookbanter.com/outlook-vba/24204-apply-photo-contact.html)

Programatix August 17th 06 11:53 AM

Apply Photo to Contact
 
Hi,

Is there a way to apply photo to a contact via VBA?

Thanks.



Ken Slovak - [MVP - Outlook] August 17th 06 03:35 PM

Apply Photo to Contact
 
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Programatix" wrote in message
...
Hi,

Is there a way to apply photo to a contact via VBA?

Thanks.



Programatix August 17th 06 04:01 PM

Apply Photo to Contact
 
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).Ite ms

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

"Ken Slovak - [MVP - Outlook]" wrote in message
...
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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Programatix" wrote in message
...
Hi,

Is there a way to apply photo to a contact via VBA?

Thanks.






All times are GMT +1. The time now is 07:12 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com