I am struggling for days on the following challenge:
Assumed you grouped your Outlook messages by conversations -- How to prevent any mail from a conversation to get marked read when double clicking on a conversation's main header?
Code I came up with so far:
- I use
Application_ItemLoad
to get the object of any selected mail - Then,
myItem_Read
to store the selected mail'sUnRead
property because it's not accessible yet at the time ofItemLoad
- Finally, I listen on the
PropertyChange
event to change back any read mail to unread. However, in the else branch below the expressionmySelection.Item(1).GetConversation.MarkAsUnread
fails unexpectedly. From my understanding,mySelection.Item(1)
selects the Conversation Header object. Then I try to obtain its Conversation object usingGetConversation
and call theMarkAsUnread
method which should in theory mark all the conversation's messages as unread again. Just theory... And I don't know why. Your help is highly appreciated.
1.
Public WithEvents myItem As Outlook.mailItem
Private Sub Application_ItemLoad(ByVal Item As Object)
If EventsDisable = True Then Exit Sub
If Item.Class = olMail Then
Set myItem = Item
End If
End Sub
2.
Private Sub myItem_Read()
If EventsDisable = True Then Exit Sub
unReadWhenSelected = myItem.UnRead
End Sub
3.
Private Sub myItem_PropertyChange(ByVal Name As String)
Dim mySelection As Selection
Dim oConvHeader As Outlook.ConversationHeader
Dim oConv As Outlook.Conversation
If EventsDisable = True Then Exit Sub
If Name = "UnRead" Then
If unReadWhenSelected = True And myItem.UnRead = False Then
Set mySelection = Outlook.ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
If mySelection.Count = 0 Then
myItem.UnRead = True
myItem.Save
Else
mySelection.Item(1).GetConversation.MarkAsUnread
End If
End If
End If
End Sub
Whole story for interested readers:
Let's say you wanted to open a conversation by double clicking its header without the conversation's elements getting marked as read. How to accomplish that in the most elegant way?
I want to use Outlook E-Mails as tasks and change the meaning of a reading a mail to finishing a task. Thus, I use search folders with the option "only show unread messages". As soon as I finish a task, I just mark it read with a macro.
But for all the other cases where I just want to read the mails etc. they need to remain unread.
So far, I managed to write a macro to accomplish this for single E-Mail messages which are not part of conversations. And when it comes to conversations, this macro works for all its elements - but not for the first one also known as the main conversation's header entry.
Edit:
Added proof-of-concept code for actually marking all emails in a conversation as read. Doesn't work in my scenario, though. So, why is this not working in my example code above?
Sub Testorino()
Dim mySelection As Selection
Set mySelection = Outlook.ActiveExplorer.Selection.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
mySelection.Item(1).GetConversation.MarkAsUnread
End Sub