#1
|
|||
|
|||
Sorting the Outlook inbox before searching for an email
Hi, I have a macro searching the Outlook inbox for a specific mail, then downloading an attachment from this email and processing it to get a specific figure and just paste it into another XL file. That's working fine so far. The issue is, the code always parses the inbox from bottom to top, that is, from the oldest item to the newest (we have it sorted so that the newest items are on top by default). That way, it will take a while since those guys never delete anything from that inbox and so there is a large number of emails there. Is there any way to either change the sorting_order of the inbox beforehand or change the order in which the loop runs (it is a FOR NEXT loop)? I've tried that >Sort< method, but that doesn't seem to work yet. Thanks a lot! Best a regards, Officer_Bierschnitt |
#2
|
|||
|
|||
HI,
Here is a code I found that may help. I remarked a area that you can review for your concern. I can not test it as to I do not have "Outlook". Code:
Private Sub Application_NewMail() Dim objNS As NameSpace Dim objFolder As MAPIFolder Dim myItem As MailItem Dim myXLApp As Excel.Application Dim myXLWB As Excel.Workbook Dim StrBody As String Dim TotalRows As Long, i As Long''' here Set objNS = GetNamespace("MAPI") Set objFolder = objNS.GetDefaultFolder(olFolderInbox) Set myItems = objFolder.Items '''' Here possible ''''' myItems.Sort "CreationTime", True Set myItem = myItems.Item(1) ''''''''''''''''' Set myXLApp = New Excel.Application myXLApp.Visible = True Set myXLWB = myXLApp.Workbooks.Open("H:\outlookitems2.xlsx") TotalRows = myXLWB.Sheets(1).Range("A65536").End(xlUp).Row i = TotalRows + 1 With myXLWB.Worksheets(1) .Cells(i, 1) = Format(myItem.SentOn, "mm/dd/yyyy") .Cells(i, 2) = Format(myItem.SentOn, "h:mm:ss AM/PM") .Cells(i, 3) = myItem.SenderName .Cells(i, 4) = myItem.To .Cells(i, 5) = myItem.Body End With With myXLWB .Save .Close End With With myXLApp .Quit End With End Sub |
#3
|
|||
|
|||
Hi Charles,
thanks! I will review the code. I have however found a different solution to my specific issue in the meantime: 1) Cleaning up the inbox a little 2) Inserting a second IF_construct in my code to look at only the emails received the current day. Best regards, Officer_Bierschnitt P.S.: From what I see, that code uses the Sort method. That should be it, nice and easy - just doesn't work in my case. Who knows why ... well, never mind. The second query for the current date does the job quite nicely. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Urgent help needed: Sorting/searching fields | cvrm | Excel | 2 | 04-17-2014 05:47 AM |
direct incoming email to "outlook" folder inbox | John Ames | Outlook | 8 | 06-25-2011 02:51 PM |
User cannot move email messages within Outlook Inbox folder and sub-folders. | Darsss | Outlook | 5 | 06-06-2011 11:37 PM |
How Do I Keep Outlook 2010 From Going Back To The Inbox After I Delete A Email | highbids | Outlook | 0 | 08-13-2010 08:51 AM |
Outlook Inbox - Email Items Productivty Counter | Nobby Norris | Outlook | 0 | 03-13-2010 01:26 AM |