I wrote the code below, which is very similar to the accepted answer here . He marks the e-mail and answers the answers as read and moves them to the archive.
I am sorting the newest mail from above. After using the macro, the following email address (older) is selected by default. I want him to move on to the next email (newer). If I canceled the sorting order of letters, then it works the way I want it. I have devoted too much time just to change the sort order of my letters.
I tried setting MailItem to Application.ActiveExplorer.CurrentFolder.Items.GetNext, and then using MailItem.Display. It opens, but does not change the choice, does not know the current choice, cannot understand what is considered "next."
I tried to set the property Application.ActiveExplorer.Selection.Item. I went through (MSDN and Expertsexchange) in search of a solution.
Sub MoveToArchive() On Error Resume Next Dim objFolder As Outlook.MAPIFolder Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem Dim objMRItem As Outlook.MeetingItem Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.Folders("Archive").Folders("Inbox") If Application.ActiveExplorer.Selection.Count = 0 Then Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.UnRead = False objItem.Move objFolder End If End If Next For Each objMRItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMeetingResponsePositive Or olMeetingResponseNegative Or olMeetingResponseTentative Then objMRItem.UnRead = False objMRItem.Move objFolder End If End If Next Set objItem = Nothing Set objMRItem = Nothing Set objFolder = Nothing Set objNS = Nothing End Sub
source share