For Each loop: Not deleting all emails

前端 未结 3 1477
忘掉有多难
忘掉有多难 2021-01-28 02:01

I wrote the below in an attempt to save emails older than six months in an external folder:

Option Explicit

Public Sub EBS()
Dim oMail As MailItem
Dim sPath As          


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-28 02:19

    You would also want to use Items.Find/FindNext or Items.Restrict instead of looping through all items in a folder.

    UPDATE:

    setItems = oInboxFolder.Items
    set RestrictedItems = setItems.Restrict(" ([ReceivedTime ] < '05/02/2014')) AND ([MessageClass] = 'IPM.Note' ")
    for I = RestrictedItems.Count to 1 step -1 do
      Set oMail = RestrictedItems.Item(I)
    next
    

提交回复
热议问题