Solved

Outlook VBA Advance Search

Posted on 2012-03-30
4
566 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
[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
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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

728 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