For Each loop: Not deleting all emails

前端 未结 3 1486
忘掉有多难
忘掉有多难 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:22

    When you delete (or move) item 1, item 2 moves into position 1. You skip that item and move on to item 3 which is now in position 2. For Each works the same way.

    One way of dealing with this is For i = oInboxFolder.Items.Count to 1 step -1

提交回复
热议问题