none
Setting Conversation Topic using Extended MAPI RRS feed

  • Question

  • Hello guys/gals, 

    I want to be able to combine mail items in outlook into a single conversation, so I may relate all threads related to a project together. My preference would be to set this up as a Macro using VBA that runs on all selected mailitems. I have the below so far, but I get a type mis-match when trying to set the value of the schema. 

    Public Sub SetSchema()
        Dim oSel As Outlook.Selection
            Set oSel = Application.ActiveExplorer.Selection
        Dim schemaGet As String, schemaSet As String
            schemaGet = "http://schemas.microsoft.com/mapi/proptag/0x0070001E"
            schemaSet = "http://schemas.microsoft.com/mapi/proptag/0x00710102"
        Dim value
        Dim i As Long
        
        value = oSel.Item(1).propertyAccessor.GetProperty(schemaGet)
          
        If oSel.Count > 1 Then
            For i = 2 To oSel.Count
                oSel.Item(i).propertyAccessor.SetProperty schemaSet, value ' the error occurs here, runtime 13, type mistach
            Next i
        End If
        
        Set oSel = Nothing
    End Sub

    Thanks in advanced for your help.

    Outlook 2010

    Windows Server 2008 R2

    * I would prefer not to install redemption as it is a server environment and it would be installed for all users. 

    Wednesday, January 8, 2014 3:15 PM

Answers

  • Thanks for your help everyone. I was able to achieve what I needed with the following code. 

    Public Sub SetSchema()
        Dim Session As RDOSession
            Set Session = CreateObject("Redemption.RDOSession")
        Dim rItem As RDOMail
        Dim convIndex As String
            convIndex = Left(Application.ActiveExplorer.Selection.Item(1).ConversationIndex, 44)
        Dim i As Long
        
        Session.MAPIOBJECT = Application.Session.MAPIOBJECT
           
        For i = 2 To Application.ActiveExplorer.Selection.Count
            Set rItem = Session.GetMessageFromID(Application.ActiveExplorer.Selection(i).EntryID)
                rItem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = convIndex
                rItem.Save
        Next i
    End Sub
    Wednesday, January 8, 2014 5:20 PM

All replies

  • 0x00710102 is a PT_BINARY property (PR_CONVERSATION_INDEX). You need to pass an array of byte as an argument, you cannot pass a string.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 8, 2014 3:18 PM
  • However, those properties cannot be set using the OOM and PropertyAccessor. Extended MAPI (or Redemption could be used, not Outlook VBA code).

    Ken Slovak MVP - Outlook

    Wednesday, January 8, 2014 3:42 PM
    Moderator
  • Public Sub SetSchema()
        Dim oSel As Outlook.Selection
            Set oSel = Application.ActiveExplorer.Selection
        Dim schemaGet, schemaSet
            schemaGet = "http://schemas.microsoft.com/mapi/proptag/0x00710102"
            schemaSet = &H710102         '"http://schemas.microsoft.com/mapi/proptag/0x00710102"  '
        Dim value
        Dim i As Long
        
        value = oSel.Item(1).propertyAccessor.GetProperty(schemaGet)
        
        If oSel.Count > 1 Then
            For i = 2 To oSel.Count
                oSel.Item(i).propertyAccessor.SetProperty schemaSet, value
            Next i
        End If
        
        Set oSel = Nothing
    End Sub

    I made the following changes, and installed Redemption (And added the reference), but now I am getting error:

    Run-Time Error 5: "Invalid Call or Argument" on the .SetProperty line

    * value variable does declare as a byte array with 0 to 21 indexes.

    Wednesday, January 8, 2014 4:04 PM
  • Hi Bjcombs1989,

    I have just tested your code on my PC with Outlook 2013 installed:

    Public Sub SetSchema()
        Dim value() As Byte
        Dim oSel As Outlook.Selection
        Set oSel = Application.ActiveExplorer.Selection
        Dim schema As String
        schema = "http://schemas.microsoft.com/mapi/proptag/0x0070001F"
            
        
        Dim i As Long
        
        value = oSel.item(1).PropertyAccessor.GetProperty(schema)
        
        If oSel.Count > 1 Then
            For i = 2 To oSel.Count
                oSel.item(i).PropertyAccessor.SetProperty schema, value
            Next i
        End If
        
        Set oSel = Nothing
    End Sub

    And I get the following error message box:

    It looks like the PropertyAccessor class doesn't allow to set a property to prevent breaking the Outlook business logic. But I was able to modify it using Extended MAPI calls.

    Finally, I have noticed that you try to automate Outlook on the server. If so, please take a look at the Considerations for server-side Automation of Office article. It states:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    Wednesday, January 8, 2014 4:26 PM
  • The product group added code to disable running object model calls when running from a service, scheduled task and in other places such as background threads in Outlook 2013. Doing so can and often will crash Outlook.

    Ken Slovak MVP - Outlook

    Wednesday, January 8, 2014 4:29 PM
    Moderator
  • With Redemption code you would get an RDOMail item and use the explicit ConversationTopic and ConversationIndex properties. RDO items do not have a PropertyAccessor object. The that was tried used Outlook object model code and not Redemption code.

    Ken Slovak MVP - Outlook

    Wednesday, January 8, 2014 4:32 PM
    Moderator
  • Or you can use RDOMail.Fields[] to set any MAPI property explicitly.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, January 8, 2014 4:39 PM
  • What is your Redemption code?

    The following code worked fine for me. Note that Redemption lets you pass the value of a binary property either as a byte array or as a hex string.

      convIndex = "01CF0C83DADF3E1A90DA193F42ABA6D83C0FE6EBE350"
      set Session = CreateObject("Redemption.RDOSession")
      Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      set rItem = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
      rItem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = convIndex
      rItem.Save


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Wednesday, January 8, 2014 4:44 PM
  • Thanks for your help everyone. I was able to achieve what I needed with the following code. 

    Public Sub SetSchema()
        Dim Session As RDOSession
            Set Session = CreateObject("Redemption.RDOSession")
        Dim rItem As RDOMail
        Dim convIndex As String
            convIndex = Left(Application.ActiveExplorer.Selection.Item(1).ConversationIndex, 44)
        Dim i As Long
        
        Session.MAPIOBJECT = Application.Session.MAPIOBJECT
           
        For i = 2 To Application.ActiveExplorer.Selection.Count
            Set rItem = Session.GetMessageFromID(Application.ActiveExplorer.Selection(i).EntryID)
                rItem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = convIndex
                rItem.Save
        Next i
    End Sub
    Wednesday, January 8, 2014 5:20 PM