[SOLVED] Outlook 2007 Macro Open Contact Folder

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The following code is what you gave me that when I select a contact, it moves to the specific folder or sub folder or sub sub folder....this is an example for a folder to a bank name....so what can I add at the end that it still moves the contact to the folder put in the code, but it also opens up that folder? Since I have many many folders, this would be helpful.

Sub MoveSelectedContactsToContacts_Marketing_Marketing_Banks_Community_Bank_of_Texas()
Dim objFolder As outlook.MAPIFolder, objInbox As outlook.MAPIFolder
Dim objNS As outlook.NameSpace, objItem As outlook.contactItem
Set objNS = Application.GetNamespace("MAPI")
Set objContacts = objNS.GetDefaultFolder(olFolderContacts)
On Error Resume Next
Set objFolder = objContacts.Folders("Marketing -").Folders("Marketing - Banks").Folders("Marketing - Banks - Community Bank of Texas")
'Assume this is a contact folder
If objFolder Is Nothing Then
MsgBox "This folder doesn’t exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a contact is selected
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olContactItem Then
If objItem.Class = olContact Then
objItem.Move objFolder
End If
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Where do I put it please in the code?
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I put it after: objItem.Move objFolder and it worked...thanks very very much!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Hope you get this question. Can we change the code so it searches the emails sent based on the email in that note field of the email message I receive....that way it shows the emails I sent to non- received contact....????
so you want to look for an address in a message body? sure, you can do that. it shouldn't take much to take the parts you need from the other macro and put them together with this one. I'm not sure i'll have time to look at it - i have a pile of work and a holiday weekend coming up.

You misunderstand....It uses the email from the message body and searches that email address in the Outlook Sent E-mail folder. that's want I want to do.

Here is the code I found that searches the Sent emails based on the contact that sent an email....so is there something in this to add and/or replace re the code that finds the contact based on the email address in the message body?

Sub SearchByAddressToContact()

Dim myOlApp As New outlook.Application
Dim ns As outlook.NameSpace
Dim strFilter As String
Dim oMail As outlook.mailItem

Set ns = myOlApp.GetNamespace("MAPI")

Set oMail = Application.ActiveExplorer.Selection.Item(1)
strFilter = oMail.SenderEmailAddress

Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
txtSearch = "to:(" & strFilter & ")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub

Above I pasted wrong so here it is:

Sub SearchByAddressToContact()

Dim myOlApp As New outlook.Application
Dim ns As outlook.NameSpace
Dim strFilter As String
Dim oMail As outlook.mailItem

Set ns = myOlApp.GetNamespace("MAPI")

Set oMail = Application.ActiveExplorer.Selection.Item(1)
strFilter = oMail.SenderEmailAddress

Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)
txtSearch = "to:(" & strFilter & ")"
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I will still wait for the Smart Woman!!:)
 

Forum Admin

Senior Member
I thought we solved this one? (I need to remember to find this thread in backups and restore the messages.)
 
Top