Solved

Search for emails by TIME, not date - o2003

Posted on 2006-11-21
7
280 Views
Last Modified: 2010-04-08
Hi,
can I search a mailbox for emails within a certain time window?  For instance - between 17:00 and 23:59?

I've tried the standard search ..Advanced Tab.. Date and Time.. Sent.. Between.. 17:00 and 23:59
and similar permutations, but they either return nothing, or everything...

A filter would also work ok, but I get the same problem - I guess the search and filter use similar formats.

Needed to identify work done out of hours - searching Inbox and Sent Items primarily, or everything....

thanks,
Danny
0
Comment
Question by:Danny Child
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17988824
Hi, Danny.

I can do this with a bit of scripting if that's an option.

Cheers!
0
 
LVL 23

Author Comment

by:Danny Child
ID: 18001963
That would work, but if it's a chore, then don't bother.  This isn't a showstopper issue.  Happy to bump the points tho! (like you need them....!)

I saw the SQL query options in the Find dialog, is that any cleverer/easier?  But as I know burger all about SQL queries, I can't suss it myself.
ta for the reply tho.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 18008916
DanCh99,

No, it's not too much of a chore.  It's an interesting problem.  Here's one possible solution.  Follow these instructions to use it.

1.  Start Outlook.
2.  Click Tools->Macro->Visual Basic Editor.
3.  If not already expanded, expand Modules and click on Module1.
4.  Copy the code below and paste it into the right-hand pane of the VB Editor.
5.  Edit the code as needed.  I placed comment lines where things need to change.
6.  Click the diskette icon on the toolbar to save the changes.
7.  Close the VB Editor.
8.  Click Tools->Macro->Security.
9.  Change the Security Level setting to Medium.
10.  Select a folder that contains mail items and run the macro.
11.  The macro outputs its results to an HTML file and then opens that file in IE when it's finished.  The messages subjects are linked back to the mail item in Outlook.


Sub FindAllMessagesInAGivenTimeframe()
    Dim datStartTime As Date, _
        datEndTime As Date, _
        datMsgTime As Date, _
        strFilename As String, _
        olkFolder As Outlook.Items, _
        olkMessage As Outlook.MailItem, _
        objFSO As Object, _
        objResults As Object
    'Change the file name and path of the output file on teh next line
    strFilename = "C:\eeTesting\Search Results.htm"
    'Change the time range to look for on the following two lines
    datStartTime = #8:00:00 AM#
    datEndTime = #12:00:00 PM#
    Set olkFolder = Application.ActiveExplorer.CurrentFolder.Items
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objResults = objFSO.CreateTextFile(strFilename)
    objResults.WriteLine "<div align=""center""><b>Search Results</b><br>"
    objResults.WriteLine "Searching folder: " & olkFolder.Parent.FolderPath & "</div>"
    objResults.WriteLine "<p><table><tr><td width=""80%""><b>Subject</b></td><td width=""20%""><b>Received</b></td></tr>"
    For Each olkMessage In olkFolder
        datMsgTime = CDate(Hour(olkMessage.ReceivedTime) & ":" & Minute(olkMessage.ReceivedTime) & ":" & Second(olkMessage.ReceivedTime))
        If (datMsgTime >= datStartTime) And (datMsgTime <= datEndTime) Then
            objResults.WriteLine "<tr><td><a href=""Outlook:" & olkMessage.EntryID & """>" & olkMessage.Subject & "</a></td><td>" & olkMessage.ReceivedTime & "</td></tr>"
        End If
    Next
    objResults.WriteLine "</table></p>"
    objResults.Close
    Set objResults = Nothing
    Set objFSO = Nothing
    Set olkMessage = Nothing
    Set olkFolder = Nothing
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "file://" & strFilename
    Do While objIE.readyState <> 4
        DoEvents
    Loop
    objIE.Visible = True
    Set objIE = Nothing
End Sub
0
 
LVL 23

Author Comment

by:Danny Child
ID: 18019452
looks good.  I'm having a bit of a mental day here, will get to test it soon.  
please bear with me...
Danny
0
 
LVL 76

Expert Comment

by:David Lee
ID: 18024014
No problem, Danny.  Take your time.  I'll be here.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 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