I rarely use VBA because I hate it. Granted, it's hate from lack of understanding; still it's hate all the same. I wrote code below that is very similar to the accepted answer here. It simply marks emails and meeting responses as read and moves them to the archive. After making a button and key assignment, it has worked very well.
The problem occurs after use. I sort my mail by newest on top. After using the macro, the selection defaults to the next email down (the older one). I want it to move to the next email up (the newer one). If I reverse the sorting order of emails, then it works how I want it to work. I've dedicated too much time into this to just reverse the sorting order of my emails. I'll start eating well, getting enough sleep, and exercising before I just reverse my sorting order.
This, I thought, was a minor issue that would be trivial to correct. I tried at first to set a MailItem to Application.ActiveExplorer.CurrentFolder.Items.GetNext then use MailItem.Display. This does a few things wrong (opens rather than changes selection, doesn't know current selection, can't figure out what's considered "next") and I've abandoned the whole path. I then tried setting the Application.ActiveExplorer.Selection.Item property, but I would like to forget that period of my life. I've been through internet Hell (MSDN and Expert*sexchange*) looking for a solution -- no success.
I have a theory that the solution to my problem is too simple to be on the internet. This is intuitive knowledge to everyone else. I, however, am genetically flawed and did not receive this knowledge instinctively.
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