Whats wrong with this code?

S

Steve

What I'm trying to do is access my outlook inbox and grab all unread
emails, received today, with subject containing "string here".
After grabbing I'm placing tab delimited data in Excel.

The above works fine almost (I'm unable to limit to just unread)

The following is where it's breaking.

Next I need to move processed emails to another folder.
When I run this macro - which I built based on code from this group.
The code is loading the emails I expect into Excel but it's moving all
unread emails to another folder.
I only want the items I process that met first series of condition

Thoughts
Steve
**** Start Code ****
Sub GetTradeSignal()
On Error Resume Next

Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim sStr As String
Dim arr As Variant
Dim i As Integer
Dim x As Long

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1

For Each olMail In Fldr.Items
If olMail.UnRead = True And _
InStr(olMail.Subject, "C2:Trade:") > 0 And _
Int(olMail.ReceivedTime) = Date Then
sStr = olMail.Body
arr = Split(sStr, " ")
x = UBound(arr) - LBound(arr) + 1
ActiveSheet.Cells(i, 1).Resize(1, x).Value = arr
i = i + 1
End If
olMail.UnRead = False
olMail.Move Fldr.Folders("Archived")
Next olMail

Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing

End Sub
****End CODE *****
 
S

Steve

Nevermind I got it.

*****
I moved
olMail.UnRead = False
olMail.Move Fldr.Folders("Archived")

Placed it after
sStr = olMail.Body

*****

I still welcome any suggestions on making this better as my computer
seems to slow down after running this.
 
S

Steve

Ok I added this to my code to start at the last low.
I seems like the code is working but the program never finishes. I just
have a blank window until I hit excape which takes me to my Excell
sheet with values loaded as expected.

What is causing the performance issue

ActiveSheet.Cells(i, 1).End(xlDown).Offset(1, 0).Resize(1, x).Value =
arr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top