Insert Photo to Contact

Status
Not open for further replies.
And I forgot to ask ......before I changed the code so it only goes to the selected contact, it add the photo to all Contacts in the default folder...as I have many many contacts in the default folder......is there simple code that removes the picture form each selected contacts....as that would be much faster as well...
 
I just figured out how to change the code we use so it removes the Picture...here is the code if that helps others

Public Sub UpdateContactPhoto2()
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

myContact.RemovePicture
myContact.Save
End If

Next
End Sub
 
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
 
To All if This Helps:

The following code adds the photo to the contact when I open the contact, select the contact, open the contact from an email I received...and of course if there are parts of it that don't need to been in there, I don't know what to take out, as I found the standard code I was given before to do it both ways, and just added to it the photo process.

Sub AddPhoto()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItem As Object
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem
strPhoto = "C:\Users\UserNaem\Pictures\NewPhotoName.jpg"
If fs.FileExists(strPhoto) Then
objItem.AddPicture strPhoto
objItem.Save
End If
GoTo Leave
End If
Set objSelection = objApp.ActiveExplorer.Selection
For Each objItem In objSelection
strPhoto = "C:\Users\UserName\Pictures\NewPhotoName.jpg"
If fs.FileExists(strPhoto) Then
objItem.AddPicture strPhoto
objItem.Save
End If
objItem.Save
Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L "Insert Pictures" Button-Wrong Folder Using Outlook 5
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
J Macro to Insert a Calendar Outlook VBA and Custom Forms 8
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
M Replyall macro with template and auto insert receptens Outlook VBA and Custom Forms 1
Z VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
B Programmatically force html send and insert clipboard contents into body Outlook VBA and Custom Forms 0
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
Witzker Outlook 2010 Insert Date & Time at the button of an OL contactform in red Using Outlook 2
P Insert link in email body to attached document in Outlook 365 Outlook VBA and Custom Forms 0
E Copy e-mail body from outlook and insert into excel Outlook VBA and Custom Forms 3
R How Do I insert images in and Auto Reply Using Outlook 3
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
Diane Poremsky Create Task or Appointment and Insert Selected Text Using Outlook 0
B Insert Hyperlinks for attachments in Userform Outlook VBA and Custom Forms 5
D Outlook task insert Outlook VBA and Custom Forms 3
A Auto Insert of filename when selecting 'Remove Attachment' Using Outlook 1
K Insert screenshots issue Using Outlook 2
makinmyway Recent Files Not Updating when Using Insert Hyperlink in Outlook 2013 Using Outlook 0
K OL2010 Button to Insert First Name Outlook VBA and Custom Forms 6
K OL2010 Button to Insert First Name Using Outlook 1
Witzker insert Date & Time (HH:mm) no (ss) in userform Using Outlook 6
A insert Date & Time in userform Using Outlook 3
K Macro to insert attachments Using Outlook 1
C Insert a Date Picker for Send Mail Subject Using Outlook 1
C Insert date in Subject through date picker Using Outlook 0
mrje1 Opening a task the Insert Tab Option is not showing up and organizing Tasks Using Outlook 9
H Insert Specific Text before Subject for New mails and reply Using Outlook 3
R insert picture tab grey Using Outlook 1
K Outlook insert clip art, no results found...address book contacts only show up Using Outlook 5
J Form design - how do I insert an automatic date/time field? Using Outlook 2
J How do I view the ruler in an Outlook message and/or insert tabs? Using Outlook 7
L Forward Email and Insert Sender's Email address in body Outlook VBA and Custom Forms 3
D Insert Text and Send Outlook VBA and Custom Forms 1
D Re: How do i insert radio buttons in an email Outlook VBA and Custom Forms 1
G How to insert a json array into a calendar events Outlook VBA and Custom Forms 1
K insert text into current position of pointer in mailcompose Outlook VBA and Custom Forms 1
J Insert File Outlook VBA and Custom Forms 2
M Insert a File Outlook VBA and Custom Forms 3
G Task / Insert / Attach Item / Business Contact BCM (Business Contact Manager) 1
M Forward email as insert from button Outlook VBA and Custom Forms 1
B Simple way to insert file text - macro? Outlook VBA and Custom Forms 1
S How to insert a picture programatically Outlook VBA and Custom Forms 12
C insert a picture Outlook VBA and Custom Forms 1
J How do I scan and insert into Outlook 2007? Using Outlook 3
B Insert information to MailItem Outlook VBA and Custom Forms 1
D RE: How do you change the default insert file path in outlook? Using Outlook 11
D Insert Text via Macro in Outlook 2007 Outlook VBA and Custom Forms 2
T Is it possible to INSERT a string into email body via Shortcut. Outlook VBA and Custom Forms 2
J Command Button to insert Email Signature Outlook VBA and Custom Forms 2

Similar threads

Back
Top