+ Reply to Thread
Results 1 to 3 of 3

Whats wrong with this code?

  1. #1
    Steve
    Guest

    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 *****


  2. #2
    Steve
    Guest

    Re: 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.


  3. #3
    Steve
    Guest

    Re: 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


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1