Thanks for the reply. The code works just fine for me also.....when certain criteria is met. Yes, the index of the mailitem is referenced using the "i" variable. Search google for "outlook vba mailitem" and the first result will give you more details. I would include a link but I have not posted enough times yet.

[vba]
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.Folders("Archived E-Mail").Folders("Inbox").Folders("Mail Failures")
Set Item = olFolder.Items(2)
Item.Display
[/vba]
The code above should open the second email in the folder by referencing its index. This is where my problem occurs. Index #1 is not always the first email in the folder. The index numbering will still run consecutively but once it reaches the end of the folder it starts back at the top. View examples below.

Ex.A: Fails at index 7 but Starts at index 1
Start of Folder
email 1 - index 7
email 2 - index 8
email 3 - index 9
email 4 - index 10
email 5 - index 1
email 6 - index 2
email 7 - index 3
email 8 - index 4
email 9 - index 5
email 10 - index 6
End of Folder


Ex.B: Works Great
Start of Folder
email 1 - index 1
email 2 - index 2
email 3 - index 3
email 4 - index 4
email 5 - index 5
email 6 - index 6
email 7 - index 7
email 8 - index 8
email 9 - index 9
email 10 - index 10
End of Folder

I added a msgbox at different stages of the loop to test each variable. I also marked all items as unread and added [vba]Item.UnRead = False[/vba] just before it looped to the next item. This showed me where the looped started and failed in the folder. I then used the script above to test each mailitem's index number. This is when I noticed that ex. A always failed and ex. B worked like a champ. To take it one step further I added a msgbox to test the strBody variable. When it came around to index 7, the strBody variable did contain the body string and it froze once it tried to parse to string. I assumed something in the body was conflicting with the regEx, so I moved items with index 1 - 6 to another folder leaving only first four items. Again, I used the script above to see if 7 - 10 became 1 - 4 and they did. Re-ran my primary script and it worked perfectly. It parsed the "problem" email plus all the rest with no issues. I am no expert, but I do not know how the regEx would be causing this issue. Again, I am no expert.

I do know that everytime the mailitem index are like ex. A, it always freezes on the mailitem that returns to the top of the folder. This is the line of code that freezes:

[vba]
Set olMatches = regEx.Execute(strBody)
[/vba]

I am sorry if I am not being clear. I do not know any other way to explain it. I do know that I have done alot of testing and if you can recreate the out of order indexes it will freeze as stated above.

Is there any way to reset the mailitem index to match the order of emails in the folder??? I think that would fix all my problems. I spent many hours searching could not find anything that resembled this problem.

Thank you again for your help,

Joshua


PS - The index counts above are examples only. They do not represent the actual amount of emails I am in need of parsing.