locked
Outlook office 365 Group - get message RRS feed

  • Question

  • Hi guys, how to get the current item in Outlook office 365 group via VBA?

    Can't seem to find a reference over the net.

    Thank you.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    • Moved by Steve Fan Monday, July 2, 2018 9:02 AM VBA related
    Monday, July 2, 2018 5:10 AM

Answers

  • Hi cguan,

    It seems that Office 365 group is a little special with other items. For example, it is organized by the conversation automatically. And actually there may be many items when you select one item like figure below(as you can see there are three items in the group but only show two item):
     

    Currently we are only able to enumerate items of Office 365 group via Application.ActiveExplorer.CurrentFolder.Items. If you want to get the current item of Office 365 group, I suggest that you submit the feedback from link below:
    Welcome to the Office Developer Platform suggestion box!

    Regards & Fei


    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.

    • Marked as answer by cguan Thursday, July 5, 2018 10:47 AM
    Thursday, July 5, 2018 7:16 AM

All replies

  • Hi,

    Welcome to the Microsoft Office for IT Professionals Outlook forum. This forum is for general questions and feedback related to Microsoft Outlook desktop application. Since your request is related to VBA, I'll move it to a more appropriate forum:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,
    Steve Fan


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, July 2, 2018 9:01 AM
  • Thanks Steve, any help guys?

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Monday, July 2, 2018 10:22 AM
  • Hello,

    The Outlook object model provides the Selection property of the Explorer class which returns a Selection object that contains the item or items that are selected in the explorer window.

    The location of a selection in the explorer can be in the view list, the appointment list or task list in the To-Do Bar, or the daily tasks list in a calendar view. For more information, see the Location property.

    The Selection property does not include any conversation header objects. Call the Selection.GetSelection method, providing olConversationHeaders as the argument, to obtain conversation header objects that are selected in the explorer.

    If the current folder displays a folder home page, this property returns an empty collection. Also, if a group header such as Today, or a conversation group header is selected, the Count property on the returned Selection object is zero.

    Sub GetSelectedItems() 
     Dim myOlExp As Outlook.Explorer 
     Dim myOlSel As Outlook.Selection 
     Dim mySender As Outlook.AddressEntry 
     Dim oMail As Outlook.MailItem 
     Dim oAppt As Outlook.AppointmentItem 
     Dim oPA As Outlook.PropertyAccessor 
     Dim strSenderID As String 
     Const PR_SENT_REPRESENTING_ENTRYID As String = _ 
     "http://schemas.microsoft.com/mapi/proptag/0x00410102" 
     Dim MsgTxt As String 
     Dim x As Long 
    
     MsgTxt = "Senders of selected items:" 
     Set myOlExp = Application.ActiveExplorer 
     Set myOlSel = myOlExp.Selection 
     For x = 1 To myOlSel.Count 
     If myOlSel.Item(x).Class = OlObjectClass.olMail Then 
       ' For mail item, use the SenderName property. 
       Set oMail = myOlSel.Item(x) 
       MsgTxt = MsgTxt &; oMail.SenderName &; ";" 
     ElseIf myOlSel.Item(x).Class = OlObjectClass.olAppointment Then 
      ' For appointment item, use the Organizser property. 
      Set oAppt = myOlSel.Item(x) 
      MsgTxt = MsgTxt &; oAppt.Organizer &; ";" 
     Else 
      ' For other items, use the property accessor to get the sender ID, 
      ' then get the address entry to display the sender name. 
      Set oPA = myOlSel.Item(x).PropertyAccessor 
      strSenderID = oPA.GetProperty(PR_SENT_REPRESENTING_ENTRYID) 
      Set mySender = Application.Session.GetAddressEntryFromID(strSenderID) 
      MsgTxt = MsgTxt &; mySender.Name &; ";" 
     End If 
     Next x 
     Debug.Print MsgTxt 
    End Sub


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, July 2, 2018 2:39 PM
  • Hi Eugene, 

    Thanks for your response, the code works for Inbox, Junk Items folder but does not seem to pick-up anything on "Groups" folder of Outlook.

    I think it's previously called Distribution list, but Outlook 2016  (O365) calls it Groups.



    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.


    • Edited by cguan Tuesday, July 3, 2018 10:53 AM edit
    Tuesday, July 3, 2018 10:10 AM
  • Did try to debug the code? 

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, July 3, 2018 12:29 PM
  • Did try to debug the code? 

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    I tried to debug the code, after this line: For x = 1 To myOlSel.Count it immediately get out of the for loop it does not even execute the if statement.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Thursday, July 5, 2018 4:26 AM
  • Hi cguan,

    It seems that Office 365 group is a little special with other items. For example, it is organized by the conversation automatically. And actually there may be many items when you select one item like figure below(as you can see there are three items in the group but only show two item):
     

    Currently we are only able to enumerate items of Office 365 group via Application.ActiveExplorer.CurrentFolder.Items. If you want to get the current item of Office 365 group, I suggest that you submit the feedback from link below:
    Welcome to the Office Developer Platform suggestion box!

    Regards & Fei


    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.

    • Marked as answer by cguan Thursday, July 5, 2018 10:47 AM
    Thursday, July 5, 2018 7:16 AM
  • Thanks Fei, that makes sense. What ever I do I just can't seem to access it.

    Cheers!


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Thursday, July 5, 2018 10:47 AM