Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Whats wrong with this code?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 31 Jan 2006 15:11 GMT
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 *****
Steve - 31 Jan 2006 15:24 GMT
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.
Steve - 31 Jan 2006 16:13 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.