Apologies if this has been answered anywhere else, I'm new to the forums and haven't seen anything previously.
I am trying to write some code, executed by hyperlink, which will create an outlook contact based on cell values within the excel spreadsheet. Whilst I can do this, I would also like to check to see if there is already a contact with the same name and if so, provide an option to update it. It is the updating of an existing contact that I am having difficulty with. Below is a snippet of the code I am using;
AddOlContact2:
mycell = ActiveCell
busvalue = "0"
'Const olContactItem = 2
Dim olContact2 As Object
Dim olupdate2 As Object
Dim olApp5 As Object
Dim Ctct2 As Object
Set olApp5 = CreateObject("Outlook.Application")
' check for existing contact
On Error Resume Next
Set olContact2 = olApp5.getnamespace("MAPI").getdefaultfolder(olfoldercontacts).items.Item(ActiveCell.Offset(0, -12) & " " & ActiveCell.Offset(0, -13))
If olContact2 <> "" Then
GoTo updateoutlookcontact2
updateoutlookcontact2:
overwrite = MsgBox("This Client's name already exists as an Outlook Contact. Do you wish to update the existing record?", vbYesNo)
If overwrite = vbYes Then
*****This is the part I cannot get to work*****
Set olupdate2 = outlookfolder.items.Find(olContact2)
Set olupdate2.FirstName = ActiveCell.Offset(0, -13)
Set olupdate2.LastName = ActiveCell.Offset(0, -14)
Set olupdate2.Email1Address = ActiveCell.Offset(0, -1)
Set olupdate2.BusinessFaxNumber = busvalue
Set olupdate2.HomeTelephoneNumber = ActiveCell.Offset(0, -3)
Set olupdate2.MobileTelephoneNumber = ActiveCell.Offset(0, -2)
Set olupdate2.HomeAddressStreet = Address
Set olupdate2.HomeAddressCity = town
Set olupdate2.HomeAddressState = county
Set olupdate2.HomeAddressPostalCode = post_code
Set olupdate2.Birthday = ActiveCell.Offset(0, -12)
olupdate2.Close olsave
***************************************************
MsgBox "Client Outlook Contact record successfully updated."
ActiveCell.Offset(0, 1) = "1"
Exit Sub
Else:
*****Everything works fine from here*****
Any help and/or guidance would be greatly appreciated
Thanks
Bookmarks