?
Solved

Outlook VBA Advance Search

Posted on 2012-03-30
4
Medium Priority
?
568 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 1500 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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