Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2015, 04:38 AM
Officer_Bierschnitt Officer_Bierschnitt is offline Sorting the Outlook inbox before searching for an email Windows 7 64bit Sorting the Outlook inbox before searching for an email Office 2013
Advanced Beginner
Sorting the Outlook inbox before searching for an email
 
Join Date: Oct 2015
Posts: 79
Officer_Bierschnitt is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 11-24-2015, 11:37 AM
charlesdh charlesdh is offline Sorting the Outlook inbox before searching for an email Windows 7 32bit Sorting the Outlook inbox before searching for an email Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 11-25-2015, 01:14 AM
Officer_Bierschnitt Officer_Bierschnitt is offline Sorting the Outlook inbox before searching for an email Windows 7 64bit Sorting the Outlook inbox before searching for an email Office 2013
Advanced Beginner
Sorting the Outlook inbox before searching for an email
 
Join Date: Oct 2015
Posts: 79
Officer_Bierschnitt is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting the Outlook inbox before searching for an email 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
Sorting the Outlook inbox before searching for an email 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft