• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to use Restrict function for filtering e-mails

ThrottleWorks

Excel Ninja
Hi,

I want to use restrict function to filter today's e-mails. I have never tried this function before. Tried Google but not able to do it.

Can anyone please guide me, how should I apply restrict function in below mentioned code.

Code:
Sub SendASN()
Dim myFolder As MAPIFolder
    Dim sFilter As String
    Dim ItemsToProcess As Outlook.Items
    Dim myItem As MailItem, myForwardItem As MailItem
    Dim MyRecipient As String
   
    Set myFolder = Session.GetDefaultFolder(olFolderInbox)
   
    'I want to use restrict function in this code
    'Criteria is today's date - email date = 0 then
    sFilter = (VBA.DateValue(VBA.Now) - Items.ReceivedTime = 0)
   
    Set ItemsToProcess = Session.GetDefaultFolder(olFolderInbox).Items.Restrict(sFilter)
   
    For Each myItem In ItemsToProcess
        If VBA.DateValue(VBA.Now) - Items.ReceivedTime = 0 Then
            MsgBox "Yo"
        End If
    Next
End Sub
 
Hi @Chihiro Sir, thanks a lot for the help. I had checked this link a while ago, but I thought I can use this through excel as well. Did not understand it.

Till your help, I was not aware about this catch. Will Google more about it and revert with details. :)
 
Back
Top