Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleApply filters to Outlook Express in Visual Basic 6
DescriptionThis example shows how to apply filters to Outlook Express in Visual Basic 6.
KeywordsOutlook Express, filter, email
CategoriesOffice
 
For some reason, my installation of Outlook Express isn't applying filters correctly and about 200 bad messages were getting through per day. This program uses SendKeys to send key strokes to Outlook Express to make it find the bad emails.

When you click one of the filter buttons, the program call subroutine ApplyFilter, passing it target From and Subject values.

 
Private Sub Command1_Click()
    ApplyFilter "Mail Delivery Subsystem", "Returned mail: " & _
        "User unknown"
End Sub
 
Subroutine ApplyFilter uses AppActivate to activate Outlook Express. It assumes the Inbox is open so the window's title is "Inbox - Outlook Express."

The program then sends Outlook Express the key strokes Alt-E, F, M to open the find dialog. It tabs to the From field and enters the target From value, tabs to the Subject field and enters that target value, and then sends the Enter key. It waits one second to give Outlook Express time to finish its search and then send Alt-E, A to select all of the found messages. (This doesn't always work the first time. I think 1 second isn't always long enough. In that case, closing the Find window and trying again usually works.)

I then manually look over the selected emails just to make sure I haven't grabbed anything I want to keep, press Delete to remove them, and press Escape to close the Find dialog. Now it takes about 20 seconds to delete the 200 or so emails that get past Outlook Express's filters.

 
Private Sub ApplyFilter(ByVal txt_from As String, ByVal _
    txt_subject As String)
Dim stop_time As Single
Dim i As Integer

    ' Activate Outlook Express.
    AppActivate "Inbox - Outlook Express", True

    ' Alt-E, F, M opens the find dialog.
    SendKeys "%E", True
    SendKeys "F", True
    SendKeys "M", True

    SendKeys "{TAB 3}", True        ' Three tabs.
    SendKeys txt_from, True         ' From:
    SendKeys "{TAB 2}", True        ' Three tabs.
    SendKeys txt_subject, True      ' Subject:
    SendKeys "{ENTER}", True        ' Search.

    ' Wait a while for the search to finish.
    stop_time = Timer + 1
    Do While Timer < stop_time
        DoEvents
    Loop

    ' Alt-E, A select all messages.
    SendKeys "%E", True
    SendKeys "A", True

    ' Let the user review the list and manually delete if
    ' desired.
    'SendKeys "{DELETE}", True       ' Delete.
    'SendKeys "{ESC}", True          ' Escape.
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated