Re: Use Instant search to find messages from a contact

Status
Not open for further replies.

KoolPal

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
My set up is OL 2010 in an exchange environment.

I learnt / tweaked from the following:

Search for messages from contact macro

and ended with this:

Code:
Sub SearchMG() 
 
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 myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox) 
     txtSearch = "from:(Email name) OR  to:(Email name) OR cc:(Email name) AND  followupflag:followup flag" 
     myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders 
 
Set myOlApp = Nothing 
 
End Sub
I am trying to save this as a Search Folder. Is that possible?

Any other way to create a search folder using Instant Search logic?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You can create a search folder using VBA - I have a sample here that creates one for the selected message sender.
http://www.slipstick.com/developer/create-an-outlook-search-folder-using-vba/

Basically, you need to add this to your code, tweaked a little of course. strFilter is your txtSearch but i'm not 100% sure your string will work - try it and see. If not, you need to use DASL filters (samples at the bottom of that page).

Code:
Dim objSearch As Search 
Set objSearch = Application.AdvancedSearch(Scope:=strScope, Filter:=strDASLFilter, SearchSubFolders:=True, Tag:="SearchFolder") 
'Save the search results to a searchfolder 
objSearch.Save (strFilter) 
Set objSearch = Nothing
 

KoolPal

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thanks! I modified my code as below, but I get an error message :(

Code:
Sub SearchMG() 
 
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 objSearch = Application.AdvancedSearch(Scope:=strScope, Filter:=strDASLFilter, SearchSubFolders:=True, Tag:="SearchFolder") 
Set myOlApp.ActiveExplorer.CurrentFolder = ns.GetDefaultFolder(olFolderInbox) 
     strFilter = "from:(Email Name) OR  to:(Email Name) OR cc:(Email Name) AND  followupflag:followup flag" 
     myOlApp.ActiveExplorer.Search txtSearch, olSearchScopeAllFolders 
 
objSearch.Save (strFilter) 
Set objSearch = Nothing 
 
Set myOlApp = Nothing 
 
End Sub
 
R

rst75

Do you want to search only the Inbox for messages from the sender of the selected message or do you want to search the entire data file?

This will create a search folder for all messages to/cc or from a person that are in the Inbox. If the folder exists, it'll error so the On Error Resume Next ends it gracefully.

Code:
Sub SearchMGm() 
Dim oMail  As Outlook.MailItem 
 
Dim strFilter As String 
Dim strScope As String 
Dim strDASLFilter As String 
Set oMail = ActiveExplorer.Selection.Item(1) 
    
 
strFilter = oMail.SenderName 
strScope = "Inbox" 
 
strDASLFilter = "((" & Chr(34) & "urn:schemas:httpmail:displaycc" & Chr(34) & " LIKE '%" & strFilter & "%' OR " & Chr(34) & "urn:schemas:httpmail:fromname" & Chr(34) & " LIKE '%" & strFilter & "%' OR " & Chr(34) & "urn:schemas:httpmail:displayto" & Chr(34) & "  LIKE '%" & strFilter & "%'))" 
 
On Error Resume Next 
Set objSearch = Application.AdvancedSearch(Scope:=strScope, filter:=strDASLFilter, SearchSubFolders:=True, Tag:="SearchFolder") 
objSearch.Save (strFilter) 
Set objSearch = Nothing 
 
Set myOlApp = Nothing 
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
If you want to search both the inbox and sent folder, use this for the scope:

Code:
strScope = "'Inbox', 'Sent Items'"
Microsoft recommends using single quotes to wrap folder names.

This DASL filter should find all flagged messages to or from the person:

Code:
strDASLFilter = "((NOT(" & Chr(34) & "urn:schemas:httpmail:messageflag" & Chr(34) & " IS NULL)) AND(" _ 
    & Chr(34) & "urn:schemas:httpmail:displaycc" & Chr(34) & " LIKE '%" _ 
    & strFilter & "%' OR " & Chr(34) & "urn:schemas:httpmail:fromname" & Chr(34) _ 
    & " LIKE '%" & strFilter & "%' OR " & Chr(34) & "urn:schemas:httpmail:displayto" & Chr(34) _ 
    & "  LIKE '%" & strFilter & "%'))"
I'd probably search for all (using the DASL filer in rst's example) and use a view to group by flag or hide unflagged messages.
 

KoolPal

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thank you both for this help. My requirement is slightly complicated.

I am trying to create a search folder for the logic given above which will search in all data stores.

I am trying to use olSearchScopeAllFolders but it's not working.

Can either help?
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
R writing "Instant Search" queries to find User-Defined fields Using Outlook 0
R Instant Search will only find items in ARCHIVE Using Outlook 3
C Interaction between Advanced Find and Instant Search in Outlook 2007 Using Outlook 1
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
B Instant search with special characters Using Outlook 1
Diane Poremsky Rebuild Outlook's Instant Search Index New Slipstick.com Articles 0
N "Instant Search" setting a default view Using Outlook 3
G Outlook 2007 compound (OR) instant search break down Using Outlook 14
B Outlook 2013 instant search fields greyed out Using Outlook 3
L Outlook 2010 Instant Search Pops When I Click Using Outlook 6
S Instant Search in Outlook 2010 Using Outlook 32
R Instant search is only searching Archive files, not all files Using Outlook 8
D Instant Search Option got DISABLED in Outlook 2007 :( Using Outlook 2
F cannt instant search in Outlook 2007 Windows 7 Public Folder, states no Items found Using Outlook 1
S Outlook 2010 Terminalserver Cache Mode Instant Search Using Outlook 4
L Windows Instant Search Indexing not working need help reading Event Log Using Outlook 2
F Instant search in secondary calendars fails using subject field Using Outlook 4
W Microsoft Outlook 2010 Instant Search Encountered a Problem While Trying to Display Results. Using Outlook 1
J Instant search greys out Outlook contact results, and has multiple greyed out results.? Using Outlook 3
B Instant search feature Using Outlook 7
K Instant search indexing status Using Outlook 1
I Outlook 2007: Search subject only, without the instant search Using Outlook 2
I Outlook 2007 instant search yielding no result even after extensive troubleshooting. please help! Using Outlook 2
E Re: Remove Outlook 2010 Instant Search Pane Using Outlook 1
G Re: Windows Search (and/or Outlook 2007 Instant Search) does not index emails from Outlook PST files Using Outlook 1
R Outlook 2010 Instant Search Doesn't Work Using Outlook 3
M Instant Search Using Outlook 2
D Instant Search in Office 10 Using Outlook 2
M How to resize the instant search pane on click on the icon to expand/ Outlook VBA and Custom Forms 1
M How to provide instant search like feature in outlook 2003? Outlook VBA and Custom Forms 1
P Disable Instant Search in Outlook 2007 Outlook VBA and Custom Forms 9
E Inbox emails appear for a brief instant and then Inbox shows no content Using Outlook 2
B Instant seach is indexing but the number of items to index that is shown in status stays the same. Using Outlook 3
M Instant message Exchange Server Administration 3
K Exchange 2003 to 2010 coexiting with Exchange 2000 Instant Messenger Exchange Server Administration 11
M Unable to enable instant messaging Using Outlook 1
L New Location for the Search Bar Using Outlook 5
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
J Outlook 2016 After a search in all mailboxes, where is each message that was found? Using Outlook 6
King Mustard Sort search groups by amount of items? Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
T Search for incoming e-mails for a specified time range Using Outlook 1
S outlook 2007 calendar search Using Outlook 6
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
J Message search and edit, another way? Outlook VBA and Custom Forms 4
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
Similar threads


















































Top