none
Save Close and Open Contact RRS feed

  • General discussion

  • I have the following two codes. The first one saves and closes the contact, and since the folder that it is in, it is still selected after closed, if I run the second code, it opens it back up. So it there a way to turn these two codes into one code that saves, closes and then opens the contact?

    Sub SaveCloseContact()

    Dim myinspector As outlook.inspector
    Dim myItem As outlook.contactItem

    Set myinspector = Application.ActiveInspector
    Set myItem = myinspector.currentItem

    myItem.Close olSave
    End Sub

    Sub OpenSelectedContact()
    Dim oContact As contactItem
    Set oContact = ActiveExplorer().Selection.item(1)

    oContact.Display

    End Sub
    I have the following two codes. The first one saves and closes the contact, and since the folder that it is in, it is still selected after closed, if I run the second code, it opens it back up. So it there a way to turn these two codes into one code that saves, closes and then opens the contact?

    Sub SaveCloseContact()

    Dim myinspector As outlook.inspector
    Dim myItem As outlook.contactItem

    Set myinspector = Application.ActiveInspector
    Set myItem = myinspector.currentItem

    myItem.Close olSave
    End Sub

    Sub OpenSelectedContact()
    Dim oContact As contactItem
    Set oContact = ActiveExplorer().Selection.item(1)

    oContact.Display

    End Sub
    Monday, July 7, 2014 9:20 PM

All replies

  • I am not sure I understand what you are trying to do - if a contact was already open, why do you need to close it and open again? Why not just call ContactItem.Save?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 7, 2014 9:32 PM
  • Sometimes when I paste an email address to the contact email1 field, I can't create an email to the person unless I save and close the contact and then open it up again....even just saving it did not work...so if the code can run where it saves and closes and then opens the contact, that it helpful....
    Monday, July 7, 2014 9:38 PM
  • Have you tried to programmatically set the ContactItem.Email1Address property call call Save?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 7, 2014 9:40 PM
  • What do you mean by that please?  Here is the code that pastes to the email1 address:

    Sub PastetoEmail1()
     Dim ex As Explorer
    Dim objApp As Application
      Dim objNS As NameSpace
      Dim objFolder As MAPIFolder
    Dim DataObj As MSForms.DataObject

    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard
      Dim ObjItem As Object
     Set ex = Application.ActiveExplorer
     
       Set objApp = CreateObject("Outlook.Application")
      Set objNS = objApp.GetNamespace("MAPI")
     
      On Error Resume Next
     
     Dim strPaste  As Variant
      
    strPaste = DataObj.GetText(1)
     
    If strPaste = False Then Exit Sub
    If strPaste = "" Then Exit Sub
     
     If TypeName(objApp.ActiveWindow) = "Inspector" Then
    Set ObjItem = objApp.ActiveInspector.currentItem
      ObjItem.UserProperties("E-mail") = strPaste
           
    ObjItem.Save
    GoTo Leave
    End If
     
     Set objSelection = objApp.ActiveExplorer.Selection
                   
               For Each ObjItem In objSelection
               
             ObjItem.UserProperties("E-mail") = strPaste
                        
            ObjItem.Save
           
            Next
    Leave:
      Set ObjItem = Nothing
      Set objFolder = Nothing
      Set objNS = Nothing
      Set objApp = Nothing
      Set DataObj = Nothing
    End Sub

    Monday, July 7, 2014 10:02 PM
  • Try using the standard Outlook property instead - Email1Address .
    Tuesday, July 8, 2014 7:53 AM
  • Thank you. Please tell me what words to replace with Email1Address.
    Tuesday, July 8, 2014 11:53 AM
  • I see that you set the "E-mail" user property, but you never set any built-in email properties.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 14, 2014 5:50 PM
  • Please explain what you saying and what to do for codes as ine code.
    Monday, July 14, 2014 6:31 PM
  • My point is that you never set the ContactItem.Email1Address property, you set some user property named "E-mail", but why would Outlook know anything about that property?

    Have you tried to replace the line

    ObjItem.UserProperties("E-mail") = strPaste

    with

    ObjItem.Email1Address= strPaste


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 14, 2014 6:40 PM
  • I did what you showed and it does paste to the email1 field of the contact...but if you see above,  I want a code that saves and closed the contact and then automatically opens it up.
    Monday, July 14, 2014 7:48 PM
  • Again, why do you need to close and reopen the contact? After setting the Email1Address property, call ObjItem.Save, and you should be able to send to the new address just fine.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 14, 2014 8:08 PM