Insert Photo to Contact

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
I saw in your area the following code for photos. Can we please change it immediately so if I copy a photo from some place online, and I run the code, it puts that photo in the photo of the contact I select or open. That would wonderful as well, as it helps doing it much faster for contacts.

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

' use myContact.LastNameAndFirstName = "last, first.jpg" format
' replace "C:\photos\" with the correct path.
strPhoto = "C:\Users\Username\Pictures" & myContact.fullname & ".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
 
You'd change the strPhoto line to use the image you found, but you'll need to use windows functions to save the image and inert it. I don't have code samples that do that. I'm on vacation so it will be a few days before i can take a look at it.
 
Got it. I appreciate you doing it as soon as possible. And in a different code I learned from you, if I paste something from what I copied, it used the words DataObj.GetFromClipboard and strPaste = DataObj.GetText(1) and objItem.UserProperties (name of field) = strPaste......

Any quick thoughts or just wait for the Smart Woman!!
 
The problem is that (AFAIK) you can't paste a picture, you need to insert an image file, so you can't just copy it, you need to save it. Plus that code works in Office, it may not work with IE or another browser.
 
Got it...so will wait to here back re the code change.....the easy way would be that copy a picture and save it to a file and the name of the picture is NewName...and then when I run the code re the contact photo, it is the photo from the file and related name NewName....that way when I just do one photo and run the macro it adds to contact...and then I select a different photo for someone else...save as the same name...and run the macro and that photo then goes to the contact I selected opened.....will wait to hear back..
 
Thanks but that is not helpful. All I want to do is select a photo from different places etc....and then run a macro that inserts that photo to photo of a contact. Now if there is a second code that after I select a photo and copy it, it saves it to a specific folder I identify and just one name, and then run the other macro that inserts the photo based on the folder and name of the photo I saved per the first code. That way, I run the first macro each time re the photo I copy, and it saves as the same name, replacing the other photo, and then I insert to another contact.
 
There's no way around, as you were already told, you cannot insert directly from the clipboard, the picture must be saved as a file. If you have an issue with file names, you can delete the file after importing it.
 
I understand ..that's why I would like the first macro that saves the photo to a folder as a file and a name the photo...that way there should be another macro that inserts the photo from a specific folder to the contact.
 
I understand your thoughts...but she always gives me the code that she knows etc.
 
I understand your thoughts...but she always gives me the code that she knows etc.
 
Also, using the code I posted, and what I saw, it can just go to a selected contact using Dim myContacts As Selection and Set myContacts = Application.ActiveExplorer.Selection......so in the strPhoto, can you tell me how I put in the fullname or where it comes from..as do I use the same full name of the contact to the photo name...or can I just use the name of the photo having nothing to do with the name of the contact?
 
strPhoto points to the file that you want to add to the contact. It must be the file's full name. As far as I know the file can be of any name. The issue you need to solve is to get the picture from the clipboard into the file.
As long as websites are concerned, you could right click the picture, then click "Save picture as" (or similar). If you always use the same location for the file and the same name, you could put that info into strPhoto, and run your code after the file was saved.
 
Thanks much...I just don't understand what to put in the code re the name of the file so the strPhoto points to the file...let's say the the name of the Photo is "NewPhotoName" ..and the path is "C:\Users\Username\ Pictures" so is the strPhoto means: strPhoto = "C:\Users\Username\ Pictures" & myContact.NewPhotoName & ".jpg" I just don't know what to change in that area of myContact.fullname and what to do there.....

Thanks so much as this could be done right away
 
Thanks much...I just don't understand what to put in the code re the name of the file so the strPhoto points to the file...let's say the the name of the Photo is "NewPhotoName" ..and the path is "C:\Users\Username\ Pictures" so is the strPhoto means: strPhoto = "C:\Users\Username\ Pictures" & myContact.NewPhotoName & ".jpg" I just don't know what to change in that area of myContact.fullname and what to do there.....

Thanks so much as this could be done right away
 
I just figured out the following and it does it perfectly....as there is no fullname etc...you just put the name of the photo after the word Pictures and it goes to ...thanks much of your time...as if I right click on a photo online and save it, I can just replace of the earlier on to the same name..

strPhoto = "C:\Users\UserName\Pictures\NewPhotoName" & ".jpg"
 
By the way, I did it before I saw your answer...and the difference is just the .jpg after the name instead of & ".jpg" so will try what you showed to see if it does the same....and thanks so so much!!!
 
And I just did your line re the jpg and it work perfectly as well.....again, thanks so much as this will be very fast in adding pictures to a contact etc...as you don't have to find the picture when you got to the contact....

And again thanks very very much!!
 
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