Solved

Outlook VBA Advance Search

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Enabling exchange 2013 read receipt 7 40
Office 2016 Add-ins GPO 3 43
Office 365 Resource Calendars aka "Rooms" 4 41
Auto BCC 8 25
Read this checklist to learn more about the 15 things you should never include in an email signature.
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: …
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…

733 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