Solved

Outlook VBA Advance Search

Posted on 2012-03-30
4
563 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
If you don't know how to downgrade, my instructions below should be helpful.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
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…

785 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