Results 1 to 2 of 2

Thread: Excel to Outlook

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Excel to Outlook

    Hello everyone,

    I haven an excel sheet containing contact information.

    In cell A1 is the firstname of the contact.

    I made a button on the excel sheet. When I press it it should UPDATE the firstname in the cell to outlook contacts.

    I have build some code wich ADDS a NEW contact to outlook.
    That code works fine.

    BUT...

    I just want to change the firstname of that contact and I dont want to add a NEW contact.

    I hope that you guys can help me.

    VB Code:
    1. Sub MakeContact()
    2.  
    3.     Dim olApp As outlook.Application
    4.     Dim olCi As outlook.ContactItem
    5.  
    6.     Set olApp = New outlook.Application
    7.     Set olCi = olApp.CreateItem(olContactItem)
    8.  
    9.  
    10.  
    11.  
    12.  
    13.     With olCi
    14.         .FirstName = Cells(1, 1)
    15. '        .LastName = "Kusleika"
    16. '        .MobileTelephoneNumber = "(402) 555-1212"
    17. '        .Email1Address = "[email protected]"
    18. '        .HomeAddressStreet = "111 S 1st"
    19. '        .HomeAddressCity = "Omaha"
    20. '        .HomeAddressState = "NE"
    21. '        .HomeAddressPostalCode = "68100"
    22. '        .SelectedMailingAddress = olHome
    23. '        .Categories = "Business, Personal"
    24.         .Save
    25.     End With
    26.  
    27.     Set olCi = Nothing
    28.     Set olApp = Nothing
    29.  
    30. End Sub

  2. #2
    Lively Member
    Join Date
    Aug 2005
    Posts
    77

    Re: Excel to Outlook

    You can try something like this:
    VB Code:
    1. Dim olApp As Outlook.Application
    2. Dim olCi As Outlook.ContactItem
    3. Dim oCF As Outlook.MAPIFolder
    4. Dim oNS As Outlook.NameSpace
    5.  
    6. Set olApp = New Outlook.Application
    7. Set oNS = olApp.GetNamespace("MAPI")
    8. Set oCF = oNS.GetDefaultFolder(olFolderContacts)
    9.  
    10. Set olCi = oCF.Items.Find("[Fullname] = " & "My name")
    11. If TypeName(olCi) = "Nothing" Then
    12.     MsgBox "Contact does not excist, so create first one."
    13. Else
    14.     MsgBox "Contact excists. You can edit this one"
    15. End If
    16.    
    17. Set olCi = Nothing
    18. Set oCF = Nothing
    19. Set oNS = Nothing
    20. olApp.Quit
    21. Set olApp = Nothing
    Last edited by [Pieter]; Nov 10th, 2006 at 03:46 AM. Reason: changed way to get contact folder
    Pieter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width