Solved

Outlook VBA not all emails moved

Posted on 2014-11-25
1
96 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now