Outlook 2007 E-mail Search

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
Per an earlier post, I learned to create a macro that for any contact I identify or open up, it will search or all emails From or To that contact. And that works great.

But, when I create a calendar event and add a shortcut to the contact, and I open the contact from that shortcut, the macro to search for emails does not work and in the debug, it colors the words:

Set oContact = ActiveExplorer.Selection.Item(1)

So there way to fix this so when I open up the contact from a shortcut to the calendar event, it will also do the search?

Thanks so much.

And the full macro is:

Sub Search_By_Address_From_and_To()


Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.Email1Address


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox)


txtSearch = "from:" & strFilter & " OR to:" & strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders


Set myOlApp = Nothing


End Sub
 
Thank you. As usual, not quite understanding your second post to this, but when changed the line to

Set oContact = myOlApp.ActiveInspector.CurrentItem

That solved it.

You should I do something different?
 
One works with opened items, one with selected items. By using the GetCurrentItem function, you can use the code with either open or selected contacts.
 
Once again....I don't understand what you are saying. Are there some specifics I now need to change.....given that the different line you gave me is now working with either an open contact or selected contact.
 
If its working, don't change it. :)
 
thanks again...you have been perfect...

so next question is how do I change this macro so searches my calendar as to all the events with that contact.....I can do that from the calendar in the normal way, but would love the macro that I create so when I select or open a contact, I am able to search the calendar in the fast was etc....

is there a way to do this?
 
2 options.

change ns.GetDefaultFolder(olFolderInbox) to ns.GetDefaultFolder(olFolderCalendar)

or, if you want to return results from all folders, change olSearchScopeAllFolders to olSearchScopeAllOutlookItems
 
Thank you. What would be the search of all folders? What folders would be searched and then how would the search show up?
 
I think there other areas to change or delete....I changed what you said but look at this macro and tell me please what else to change or delete as there are other email type areas and I don't know what to do

Sub Search_Calender()

Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.Email1Address


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderCalendar)


txtSearch = "to:" & strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
 
All folders is all folders of the item type - in the case of olcalendar, it would be all calendar folders in the profile.

- - - Updated - - -

That looks correct - it works here.
 
did not work ..said unexpected end sub ...the line "Sub Search_Calender()" is colored yellow and the line "txtSearch" is colored blue

the macro is:

Sub Search_Calender()

Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.Email1Address


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderCalendar)


txtSearch = "to:" & strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders
 
you are missing the end of the code -
txtSearch = "to:" & strFilter
myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing
End Sub
 
That worked...thanks very much....

The only question is.....is it researching calendar based on the full name of the contact as it shows up searching for the email address and yet the calendar appointments to the name of that email address do show up...so what is it searching?

And is there a way to make sure it searches based on the full name of the contact?
 
Yes..I looked into even more and searches based on the name of the email address..so if the full name was Tom Smith and the email was tsmith, the Tom Smith appointments do not show up....so can we change the macro so it searches the calendar based on the full name of the contact and not the name of the email?

Thanks much
 
You need to use .fullname instead of .email1address.
 
Thank you.

So the line: ' use oContact.FullName to search on the name

strFilter = oContact.Email1Address should be changed to

' use oContact.FullName to search on the name

strFilter = oContact.fullname correct?

and the line txtSearch = "to:" & strFilter should be changed to txtSearch = strFilter is that correct?

And last, if the search is not the fullname but just the last name, change the word "fullname" to "lastname"?

So
 
This is what I did, and it works:

Sub Search_Calender()

Dim myOlApp As New Outlook.Application

Dim ns As Outlook.NameSpace

Dim strFilter As String

Dim oContact As Outlook.ContactItem


Set ns = myOlApp.GetNamespace("MAPI")


Set oContact = ActiveExplorer.Selection.Item(1)


' use oContact.FullName to search on the name

strFilter = oContact.LastName


Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderCalendar)


txtSearch = strFilter

myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders

Set myOlApp = Nothing

End Sub
 
correct on the name question.

I think you can still use To: in the query... also, if you want to restrict it to full name together, not all the john's and all the does, use "john+doe" - or in the case of the code, .firstname & "+" & .lastname
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
D Outlook 2007 e-mail header- How to set font & font size in received message headers ? Using Outlook 2
C in outlook 2007-Contact Group-One name have 3 mail id-its possible? Using Outlook 3
D Recover deleted Outlook 2007 e-mail account Using Outlook 1
L Outlook 2007 Macro Reply to E-mail Using Outlook 16
L Outlook 2007 Search Through E-Mail Using Outlook 41
L Outlook 2007 E-Mail From Selected Task Using Outlook 18
R Outlook 2007 junk mail Using Outlook 4
F Using Outlook 2007 as an IMAP Mail Station Without Saving Data Locally Using Outlook 2
L Outlook 2007 Distibution E-mail Structure Using Outlook 5
W Combine Mail Merge to Distribution List with Auto Attachments - Outlook 2007 Using Outlook 1
D Problem with MS mail and outlook 2007 OS Windows 8 Using Outlook 1
D Can't Use Contacts with Mail & iCloud in Outlook 2007 Using Outlook 7
L Outlook 2007 E-Mail Search Using Outlook 9
P help me plase !!! outlook 2007 I can see mail Bcc Using Outlook 1
C MS Mail and Outlook 2007 Using Outlook 3
B Outlook 2007 Mail Accounts Order? Using Outlook 2
L Outlook 2007 - How to remove account without removing mail folders? Using Outlook 4
D Sort e-mail by sender's domain - Outlook 2007 Using Outlook 2
N Providing a reference to incoming mail in outlook 2007 BCM (Business Contact Manager) 2
W Outlook exp. 2007 problems - won't receive new mail Using Outlook 1
A Outlook 2007 Mail Merge not working anymore Using Outlook 1
L How can I delete stationery from Actions, New Mail Message Using in outlook 2007? Using Outlook 6
S Outlook 2007 Macro for replying to an e-mail. Outlook VBA and Custom Forms 1
C Importing emails/contacts to Outlook 2007 from Windows Mail Outlook VBA and Custom Forms 3
C How do I enable a link in an e-mail in Outlook 2007? Using Outlook 4
A How to Sort by Unread and then Read mail in Outlook 2007 Using Outlook 7
D Outlook 2007 Will Not Send Mail From C# Application Outlook VBA and Custom Forms 7
N Automating Outlook 2007 problem with sending mail Outlook VBA and Custom Forms 1
D Disable Junk E-mail Filter in Outlook 2007 Using Outlook 13
X open specific e-mail messages in outlook 2007 c# Outlook VBA and Custom Forms 1
T need help w/ sending an e-mail -- outlook 2007 addin Outlook VBA and Custom Forms 2
B Outlook 2003/2007 and New Mail Desktop Alerts Outlook VBA and Custom Forms 4
D Outlook 2007 Recovering E-Mails Using Outlook 0
W Transfer Outlook 2016 autocomplete file to Outlook 2007 Using Outlook 1
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
S Outlook 2007 crash linked to gdiplus.dll Using Outlook 0
S Outlook 2007 - Automatic purge fail Using Outlook 0
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
D Outlook 2007 vs. Outlook 2010 -- ToDo Bar Using Outlook 0
D Outlook 2007 on 365 Using Outlook.com accounts in Outlook 2
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 23
S Verwendung von Outlook 2007 Using Outlook 0
M PST import from Outlook 2007 to 2010 - Address Book contacts all in 1 group Using Outlook 4
S outlook 2007 calendar search Using Outlook 6
B Migrate Outlook 2007 to Office 365 Using Outlook 3
X I have met my waterloo trying to resolve embedded graphics problem with outlook 2007 and now 2016 Using Outlook 1
R Outlook 2007 only loads some appointments Using Outlook 0
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
J Outlook 2007 Hide Messages Option not Available Using Outlook 2

Similar threads

Back
Top