I also have ask right away as we did the same for another code and I can' t remember exactly what we did.
In the past we had codes that worked when we select or open a contact, but if we open the contact from the email we received there was something else to add to the code, so the code worked as to contact that was opened up from the email received and not from the contact folder. So here is the full code we know have for the photo and it works for the selected contacts or open contact, but not if the contact is opened from the email received....so please tell me again what I need to adjust so it works when the contact is opened from the email received and not from the contact folder.
Public Sub AddPhoto()
Dim myOlApp As outlook.Application
Dim myNamespace As outlook.NameSpace
Dim myContacts As Selection
Dim myItems As outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = Application.ActiveExplorer.Selection
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
' use myContact.LastNameAndFirstName = "last, first.jpg" format
' replace "C:\photos\" with the correct path.
strPhoto = "C:\Users\UserName\Pictures\NewPhotoName.jpg"
' use for testing only, to confirm the path is correct.
' Delete or comment out
' MsgBox (strPhoto)
If fs.FileExists(strPhoto) Then
myContact.AddPicture strPhoto
myContact.Save
End If
End If
Next
End Sub