Solved

Outlook VBA not all emails moved

Posted on 2014-11-25
1
102 Views
Last Modified: 2014-12-04
Each time I run this code, only some emails are moved.  I have to run it 3 to 5 times to get all of them moved.

 For Each oItem In oFolder.Items
    If TypeName(oItem) = "MailItem" Then
        If Left(oItem.Subject, 31) = "Information about your order (#" And oItem.ReceivedTime > #11/23/2014# Then
            oItem.Move oDestFolder
            Debug.Print oItem.Subject
        End If
    End If
 Next

Open in new window

0
Comment
Question by:rrhandle8
[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
1 Comment
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40465787
Try moving them in reverse order. When you move items out of a collection it stuffs the indexing up.

See code below... just written here, not tested but should work. I do this on a regular basis with Outlook mailitems.

itemCount = oFolder.items.count
 For i from itemcount to 1 step -1
set oItem = ofolder.items(i)
    If TypeName(oItem) = "MailItem" Then
        If Left(oItem.Subject, 31) = "Information about your order (#" And oItem.ReceivedTime > #11/23/2014# Then
            oItem.Move oDestFolder
            Debug.Print oItem.Subject
        End If
    End If
 Next i

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

734 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