Change selected item to next or previous

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 
+1
source share
4 answers

Outlook does not offer programmatically selecting a specific item in the Explorer window. That way you can do it that way. The only way I could do this is to programmatically press the previous key on the toolbar or menu. or update the archiving application in the inspector, etc.

+2
source

Paste one of the two lines of SendKeys code into your code from one of the following two macros to force Outlook to change the selection in the Outlook item list pane to a message above or below the active message. The email item that you move up or down must be active in the Item List pane in Outlook before executing the SendKeys code. If necessary, add a time delay to your code to allow time for the corresponding message to become active in Outlook before the SendKeys code is executed. You can also add these macros to the ribbon in Outlook 2010 to create up and down arrow buttons to navigate in the Outlook item list pane.

- Sub MoveUp ()

SendKeys "{UP}": DoEvents

End sub

Sub MoveDown ()

SendKeys "{Down}": DoEvents

End sub

+2
source

I managed to achieve a similar effect using the SendKeys function.

I wanted to return to the first message in Explorer, after doing some manipulation of the selected elements.

After doing the manipulation, I added the following line:

 SendKeys "{HOME}" 

This works for me in this particular case, but can be changed for use in a different context.

+1
source

Use clearselection and addtoselection , like this

 Call e.ClearSelection For Each itt In e.CurrentFolder.Items 'MsgBox CStr(itt) If (e.IsItemSelectableInView(itt)) Then If itt.FullName = it.FullName Then Call e.AddToSelection(itt) End If End If Next 
0
source

All Articles