I am using the RDCOMClient package in R. I am trying to run a for loop on the Outlook Inbox folder in order to select the last email received by a sender. The goal is to automatically upload an Excel sheet sent as an attachment in this email (which has as subject a name that always starts with the same words). This means that I loop through the emails until I find this specific email based on the Subject name.
I created a code that allows me to achieve this goal. So far, I have had no problem, but now when I run the code the for loop skips some emails that are ordered by date in my Outlook Inbox folder. To Force the for loop to iterate. To force for loop to iterate on emails without skipping any of them I thought to force the email order based on the dates on which I received them (in fact the email I want to select is the last received by the specific sender). How can I order the emails based on the dates before looping through them?