Outlook 2007 Macro Save Contact

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I have a code that when I copy a email address from another place, I open up a contact and there is a macro that pastes it to the email address. But if I don't save the contact and close it, and open it up, it does not use that email address yet. So is there a macro that saves the contact or saves it, closes it, and opens it, so that way I had that code to the paste code, and it is all done right away. Thanks very much to the Smart Woman!!!:)
 

Forum Admin

Senior Member
Does it need closed and reopened or just saved?
If your object variable is oContact, you'd use this to save it:
oContact.Save

Or, try resolving the address (I'm not sure of the correct code - my brain is still on holiday :))
.Resolve
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Just pull out the end sub and the next sub name.

Code:
Sub SaveCloseContact()

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

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

myItem.Close olSave

Set oContact = ActiveExplorer().Selection.item(1)
oContact.Display

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I tried that earlier but there was an error where "oContact.Display" is colored as yellow but no error message
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I don't know - it works here (with outlook 2013).
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
It might be that it runs the second code a little to early as maybe it does not yet recogize a selection yet. Because when i run it a second time it works. So is there a way to add to your code a code that waits to move foward in the macro for a short period of some time?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Outlook doesn't have a timer, so there really isn't an easy way to delay it. Add an on error resume next to the macro - what happens?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Please tell me what words and exactly where to add them.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Code:
Sub SaveCloseContact()
Dim myinspector As outlook.inspector
Dim myItem As outlook.contactItem
Dim oContact As contactItem
Set myinspector = Application.ActiveInspector
Set myItem = myinspector.currentItem
myItem.Close olSave

on error resume next

Set oContact = ActiveExplorer().Selection.item(1)
oContact.Display
End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
What you gave me has it now show up a yellow line, but it does not open up the contact still
 
Top