locked
Cannot retrieve email items in collapsed groups with GetSelection() RRS feed

  • Question

  • >
    I am trying to parse messages based on selection. This is not a problem when selecting messages, however if I select a collapsed group it is not working. The code I wrote is based on my understanding that a collapsed group is a conversation and I have to get  conversations through GetSelection(Outlook.OlSelectionContents.olConversationHeaders) - but it returns nothing. 

    Is there another way to access collapsed groups?

    If selectedMessages.Count > 0 Then
        ' Mail items selected
        For Each message In selectedMessages
            If TypeOf message Is Outlook.mailItem Then
                Set emailItem = message
                ' here handle item
            End If
        Next message
    Else
        ' Conversation headers selected
        Set conversations = selectedMessages.GetSelection(Outlook.OlSelectionContents.olConversationHeaders)
        For Each header In conversations
            For Each item In header.GetItems()
                If TypeOf item Is Outlook.mailItem Then
                    Set emailItem = item
                    ' here handle item
                End If
            Next item
        Next header
    End If
    Debug of code above shows no conversations were found:



    I did try the code with true conversations when the view is set with "show as conversations" and it does work, but that is not what I need. I am NOT looking for items grouped through threaded conversations. I am looking to find the email items in a collapsed group such as "Today" when sorted by date, or all emails under collapsed group with header "foo@bar.com" when sorted by from.

    Any clues?





    • Edited by J. Farro Tuesday, June 6, 2017 4:33 PM
    Tuesday, June 6, 2017 12:24 PM

All replies

  • Hi J.Farro,

    According to Selection.GetSelection Method:

    If the current view is not a conversation view, or, if Location is not equal to OlSelectionLocation.olViewList, calling GetSelection with olConversationHeaders as the argument returns a Selection object with Count equal to 0.

    So Selection.Count will always be 0 if you don't set the current view as a conversation view. However, in my test, whatever I set "show as conversations", the count is still 0. How do you get this work? Could tell me your steps?

    Do you have any specific group you want to get? Maybe you could use Items.Restrict to get a specific group.

    Best Regards,

    Terry

    Wednesday, June 7, 2017 10:51 AM

  • Terry,

    There are two types of grouping possible. One is when you set "Show as conversations", and then messages appear threaded. My concern is the other grouping, when messages are grouped based on the sorting order. So for example if you sort by "From", the explorer window will show the groups either expanded as such:

    Or the explorer window will look as such when 3 groups are collapsed:

    Now to the important point: note that the current selection in the collapsed group is "IoTi Informer". I want to retrieve all messages in that selection, and the code I am using is not working, so my question was - how do you access those messages?

    Note I cannot use Item.Restrict because there is no item selected. The count returns 0, there are no headers and no conversations, at least not with the code I was using. So there must be another way....


    • Edited by J. Farro Wednesday, June 7, 2017 2:53 PM
    Wednesday, June 7, 2017 2:50 PM
  • Hello,

    According to Explorer.Selection Property (Outlook) and Selection.GetSelection Method (Outlook):

    if a group header such as Today, or a conversation group header is selected, the Count property on the returned Selection object is zero.

    If the current view is not a conversation view, or, if Selection.Location is not equal to OlSelectionLocation.olViewList, calling GetSelection with olConversationHeaders as the argument returns a Selection object with Selection.Count equal to 0.

    I think there is no method to get the selected group as your wish. 

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 13, 2017 6:43 AM

  • I think there is no method to get the selected group as your wish. 

    Regards,

    Celeste



    Celeste, we agree - right now this is not working and maybe this was not made for that purpose, however for completeness of the API we must have a way of knowing what is selected in the explorer window, so can you please forward to the powers that be a request to either make GetSelection(Outlook.OlSelectionContents.olConversationHeaders)  work also with grouped headers , or alternatively add a new constant:
    GetSelection(Outlook.OlSelectionContents.olGroupedHeaders)

    Wednesday, June 14, 2017 3:38 PM
  • Hi J. Farro,

    You could connect Outlook User Voice to make suggestions. Thanks for your understanding.

    Best Regards,

    Terry

    Friday, June 16, 2017 8:48 AM
  • I am curious to know if this problem has been resolved, or anyone found an alternative solution to this.

    Pradeep, Microsoft MVP (Visual Basic)
    http://pradeep1210.wordpress.com

    Friday, March 30, 2018 8:02 AM