Solved

Can you search Outlook messages like a database (sort of query for a list of items contained in messages: body, subject, or attachment name)

Posted on 2014-11-04
9
349 Views
Last Modified: 2014-11-19
In Outlook 2010/2013, is there a way to take a list of numbers/codes (simple numerical items) and find if they exist in a specific outlook folder?  The could exist in either the body, subject or in the name of an attachment.  It would be nice to be able to know not only that it was found, but in which section(s) as well.

Note: This is not exchange.  Stand alone Outlook only.
0
Comment
Question by:Ray
  • 5
  • 3
9 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 40441007
Yes, that can be done
http://msdn.microsoft.com/en-us/library/office/ff866933(v=office.15).aspx
I suspect though, that you'd need to create a UserForm as a place to enter the strings you'd like and perhaps the results as well.  There could be a fair bit of heavy lifting to that.

How are your Outlook VBA skills?
0
 
LVL 10

Author Comment

by:Ray
ID: 40441047
My Outlook VBA skills are only as good as the skills that will transfer from Excel VBA skills.  Sounding like not good enough though.

What i see from the msdn article doesn't appear to give me the ability to look for a list of things (such as 50-100 different job numbers) and return the results of each of those in a table format (I was likely unclear about wanting a table of results).
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40441105
All things are possible because Application.AdvancedSearch exists.
Since you know Excel VBA, that's maybe where you should do this from.
I'm an Access guy, primarily, but the guts of it are the same.
This code goes in a module and is used to start Outlook

Option Explicit
Public wasOpen As Boolean
Function StartApp(ByVal appName) As Object
On Error GoTo ErrorHandler
Dim oApp As Object

wasOpen = True
Set oApp = GetObject(, appName)    'Error here - Run-time error '429':
Set StartApp = oApp

Exit Function

ErrorHandler:
If Err.Number = 429 Then
    'App is not running; open app with CreateObject
    Set oApp = CreateObject(appName)
    wasOpen = False
    Resume Next
Else
    MsgBox Err.Number & " " & Err.Description
End If
End Function

Open in new window


This code, probably in Excel fired from a macro, gets you an Outlook.Application object to work with

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim objOutlookExplorers As Outlook.Explorers


Set objOutlook = StartApp("Outlook.Application")

Dim ns As Outlook.Namespace
Dim Folder As Outlook.MAPIFolder
Set ns = objOutlook.GetNamespace("MAPI")
Set Folder = ns.GetDefaultFolder(olFolderInbox)
Set objOutlookExplorers = objOutlook.Explorers

If wasOpen = False Then
    objOutlookExplorers.Add Folder
    Folder.Display
    'done opening
End If

Open in new window


Now, from there, from the second example in the linked MSDN article you be looking to set the parameters of
expression .AdvancedSearch(Scope, Filter, SearchSubFolders, Tag) with Excel cell values
Set up this way, where expression would be Application if you were doing it in Outlook, it will be objOutlook

And, at the end of the second example
   Do Until MyTable.EndOfTable  
        Set nextRow = MyTable.GetNextRow()  
       Debug.Print nextRow("Subject")  
    Loop  

Instead of Debug.Print, you'll be looking to write results to Excel cells

Let me know what you think
0
 
LVL 10

Author Comment

by:Ray
ID: 40442762
Nick,
At first glance, I think you're right in the range of what I need.  It'll be a week or two before I really get to sit down and try it out.  Since it is miles ahead of where i started, I'm going to mark this as the answer and close the question.

Thank you for leading me down the path to a solution!
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 26

Expert Comment

by:Nick67
ID: 40443019
I think you should be able to leave it open.  Don't mark it as answered until it really does have finality for you.
On my part, there's no hurry.

Nick67
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 500 total points
ID: 40443184
Have a gander at this
http://www.gregthatcher.com/Scripts/VBA/Outlook/GetListOfOutlookEmails.aspx
What version of Outlook are you targeting?

Here's a solid start on what you need.
I've tested it under Outlook 2013 (so you may need to fix the reference if you are downlevel from that) and it does the job.
More detail on filtering here
http://msdn.microsoft.com/en-us/library/office/ff863965(v=office.15).aspx

And probably you'll want to look to see how to pop more details that just 'Subject' onto the results worksheet.

From there, you're looking at creating code that will get Outlook to display the message you select from the Excel sheet.  Fun!
What I've seen so far requires O2007+
Search-Outlook.xlt
0
 
LVL 10

Author Closing Comment

by:Ray
ID: 40453772
After some looking, this will get me there with a bit more time spent.  Thanks for your help!!
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40453927
Then there's the round-trip, so to speak.
With the details knock into the spreadsheet, you should be able to craft code in Excel that will have Outlook find and select the message of the active cell if that's what you're also after.

AdvancedSearch also permits multiple search criteria.  I only set up for a single row in Excel, but that is certainly extensible.
You may find this of interest, as well
http://www.gregthatcher.com/Scripts/VBA/Outlook/GetListOfOutlookEmails.aspx

Glad to be of service!
Nick67
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Are you irritated by repeating emails issue in Microsoft Outlook 2016 after recent update ?  Lets’ see how to resolve and prevent duplicate emails in the Outlook 2016 using some simple techniques.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now