Solved

Outlook VBA Advance Search

Posted on 2012-03-30
4
561 Views
Last Modified: 2012-06-27
Hi Team,

I want to use the Advance search option with subject and also with the eamil sent time in VBA.

Can you please provide me with the sample codes for the same.

Thanks,
Sandesh.
0
Comment
Question by:Sandesh555
  • 3
4 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37790085
Personally I prefer to use a filter when in VBA where there is an example here ... but someone else is addressing advanced search therein so check out:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_27633498.html

Chris
0
 

Author Comment

by:Sandesh555
ID: 37791374
Hi Chris,

Can you give me more details of how to use Filters.   I would be instrersed to know the same.

Thanks,
Sandesh.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37791389
One of the last posts in that question is a specific example but here it is as well:

Sub taskFilterCorp()
Dim olFolder As Object
Dim filteredItems As Object
Dim folderItems As Object
Dim sorteditems As Object
Dim strFilter As String
Dim itm As Object

    Set olFolder = Application.Session.GetDefaultFolder(olFolderInbox)
    Set folderItems = olFolder.Items
    strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like " & "'%" & "corp" & "%'"
    Set filteredItems = olFolder.Items.Restrict(strFilter)
    
    If filteredItems.Count = 0 Then
        MsgBox "No such tasks found"
    Else
        For Each itm In filteredItems
            Debug.Print itm.Subject
        Next
    End If

End Sub

Open in new window


Specifically the requirement was a wildcard search on the subject for the string corp.  Whilst it was within the tasks folder, with the inbox selected above it works for mails exactly the same.


Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 37791395
A similar entry from a different question that shows the use of time in the sent items folder is as follows:

    Set myfolder = application.session.GetDefaultFolder(olFolderSentMail)
    strfilter = "[SentOn] >= '" & Format(Date + TimeSerial(0, 0, 0), "ddddd h:nn AMPM") & "'" & " and " & "[senton] <= '" & Format(Date + TimeSerial(23, 59, 59), "ddddd h:nn AMPM") & "'"
    Set olmailitems = myfolder.items.Restrict(strfilter)

Open in new window


Chris
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

10 Experts available now in Live!

Get 1:1 Help Now