Dathan Camacho
New Member
- Joined
- Mar 30, 2010
- Messages
- 37
Our IT department set up a data feed that sends me data in the body of an email. The macro below extracts the data and sends it to a text file.
Here's the problem - the query processes half the files and then fails. If I restart it, it processes half of the remaining files, then fails.
E.g: If I start w/244 files, it processes 122 files and stops. If I restart the query, it then processes half of the remaining 122 files and stops with 61 files remaining. I continue restarting until all are processed. Can someone review the code and help me understand why? Thanks!
Here's the problem - the query processes half the files and then fails. If I restart it, it processes half of the remaining files, then fails.
E.g: If I start w/244 files, it processes 122 files and stops. If I restart the query, it then processes half of the remaining 122 files and stops with 61 files remaining. I continue restarting until all are processed. Can someone review the code and help me understand why? Thanks!
Code:
Public Sub Move_BP_Files()
Dim EmailSubject As String
Dim EmailBody As String
Dim EmailSenderName As String
Dim BodyData As String
Dim IsOldFileData As Boolean
Dim UserIDData As String
Dim NumberOfFilesData As Integer
Dim myItems As Outlook.Items
Dim MYNewBody As String
Set myItems = Application.GetNamespace("MAPI").Folders("Personal Folders").Folders("$$$ BP Sort Data").Items
For X = 1 To myItems.Count
EmailSubject = Trim(myItems.Item(X).Subject)
EmailBody = Trim(myItems.Item(X).Body)
EmailSenderName = myItems.Item(X).SenderName
MYNewBody = "|"
For Z = 1 To Len(EmailBody)
If Mid(EmailBody, Z, 1) = ":" Then
MYNewBody = MYNewBody & "|"
Else
MYNewBody = MYNewBody & Mid(EmailBody, Z, 1)
End If
Next Z
Open "X:\Scan Results from 53 Stores\OUTLOOK_EXPORT.txt" For Append As #1
Write #1, MYNewBody
Close #1
myItems.Remove (X)
Next X
MsgBox "Done"