Outlook Macro

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!

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"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,225,531
Messages
6,185,482
Members
453,297
Latest member
alvintranvcu123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top