![]() |
Whats wrong with this code?
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 ***** |
Whats wrong with this code?
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. |
Whats wrong with this code?
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 |
All times are GMT +1. The time now is 11:20 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com