How to select an mailitem in explorer with "show as conversation"

Status
Not open for further replies.

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,
I want to extend a code from Mickael BAUER.

From an Mailitem i want to display an explorer with this Email selected
BUT IF THE FOLDER IS mark "Show as conversation", the code is wrong

how select an Email in cconversation mode ?
how turn off/on conversation mode for just this folder ?

Code:
Public Sub GetItemsFolderPath()
    Dim obj As Object
    Dim F As Outlook.MAPIFolder
    Dim NewExpl As Explorer
    Dim Msg$
    Set obj = Application.ActiveWindow
    If TypeOf obj Is Outlook.Inspector Then
        Set obj = obj.CurrentItem
    Else
        Set obj = obj.Selection(1)
    End If
    Set F = obj.Parent
    Msg = "The path is: " & F.FolderPath & vbCrLf
    Msg = Msg & "Switch to the folder?"
    If MsgBox(Msg, vbYesNo) = vbYes Then
        Set NewExpl = Application.Explorers.add(F, olFolderDisplayFolderOnly)

       
        NewExpl.Activate
        Set acticselection = NewExpl.Selection.item(1)
        On Error GoTo Errohandler
        NewExpl.ClearSelection
        NewExpl.AddToSelection obj
        NewExpl.RemoveFromSelection acticselection


        NewExpl.Display
        NewExpl.WindowState = olMaximized
    End If

    Exit Sub
Errohandler:
    MsgBox Err & vbCr & Err.Description
   
    '        Dim colCB, objCBB
    '        Set colCB = NewExpl.CommandBars
    '
    '        If Not NewExpl Is Nothing Then
    '            If NewExpl.CommandBars.GetPressedMso("ShowInConversations") Then
    '                NewExpl.CommandBars.ExecuteMso ("ShowInConversations")
    '            End If
    '
    '        End If
    '        'NewExpl.CurrentView
    '        NewExpl.ClearSelection
    Resume
End Sub

Sub DemoConversationTable()
    Dim oConv As Outlook.Conversation
    Dim oTable As Outlook.table
    Dim oRow As Outlook.Row
    Dim oMail As Outlook.MailItem
    Dim oItem As Outlook.MailItem
    Const PR_STORE_ENTRYID As String = _
          "http://schemas.microsoft.com/mapi/proptag/0x0FFB0102"

    On Error Resume Next
    ' Obtain the current item for the active inspector.
    Set oMail = Application.ActiveInspector.CurrentItem

    If Not (oMail Is Nothing) Then
        ' Obtain the Conversation object.
        Set oConv = oMail.GetConversation
        If Not (oConv Is Nothing) Then
            Set oTable = oConv.GetTable
            oTable.Columns.add (PR_STORE_ENTRYID)
            Do Until oTable.EndOfTable
                Set oRow = oTable.GetNextRow
                ' Use EntryID and StoreID to open the item.
                Set oItem = Application.Session.GetItemFromID( _
                            oRow("EntryID"), _
                            oRow.BinaryToString(PR_STORE_ENTRYID))
                Debug.Print oItem.subject, _
                            "Attachments.Count=" & oItem.Attachments.Count
            Loop
        End If
    End If
End Sub
 

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,
When the folder is set "Show as conversation", there is an error '-2147467259 (80004005)
"la méthode appelée n'est pas valide pour une vue de conversation" (in french) on clearSelection, AddToSelection and Removefromselection
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
MSDN doesn't say anything about an error for the conversation view. According to it, it throws an error only if the item is being edited, no matter which view it is. So, in your error handler handle that error, and prompt the user to first cancel the edit mode, then let him call the function again.

What could throw err 9 is that Selection.Count is 0 directly after displaying the explorer. Adding a DoEvents solves it:
Code:
set newexpl=...
newexpl.display
doevents
...
Here it makes no difference, however, it's not logical that you first want to activate the explorer, then display it. Maybe that's an issue for you as an object that isn't already visible cannot be activated (activating it has to do with setting the focus on it, so it must be visible already).

BTW: "Resume" in your error handler calls the error throwing line again and again. That makes no sense if the user isn't able to solve the error. "Resume Next" would call the next line, which would also make no sense in this context. Both options could make sense, for instance, for user input errors but not for programming errors.
 

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi Michael,
I agree with you ! But my code is an alpha version, so it lacks instructions in the ErrorHandler, to handle the case folders with the "show in conversation", and other instructions were there, to test other ways.

I wanted to uncheck the "show in conversations" option with msoexecute , then check it after the selection, but there is a dialog box that asks if you want to do it on all folders or just this one, and I have not been able to validate this box with sendkeys "{enter}".

Is there a solution to do otherwise?

Is there a solution to select an item in explorer otherwise ?

Code:
Public Sub GetItemsFolderPath()
    Dim obj As Object
    Dim F As Outlook.MAPIFolder
    Dim NewExpl As Explorer
    Dim Msg$
    Dim ShowInConversations As Boolean
    Set obj = Application.ActiveWindow
    If TypeOf obj Is Outlook.Inspector Then
        Set obj = obj.CurrentItem
    Else
        Set obj = obj.Selection(1)
    End If
    Set F = obj.Parent
    Msg = "The path is: " & F.FolderPath & vbCrLf
    Msg = Msg & "Switch to the folder?"
    If MsgBox(Msg, vbYesNo) = vbYes Then
        Set NewExpl = Application.Explorers.add(F, olFolderDisplayFolderOnly)

        NewExpl.Activate
        DoEvents
        'Set acticselection = NewExpl.Selection.item(1)
        On Error GoTo Errohandler
        NewExpl.ClearSelection
        NewExpl.AddToSelection obj
        'NewExpl.RemoveFromSelection acticselection

        NewExpl.Display
        NewExpl.WindowState = olMaximized
    End If

    If ShowInConversations Then
        MsgBox "please press [enter] on next dialog box"
        NewExpl.CommandBars.ExecuteMso ("ShowInConversations")
    End If
    Exit Sub
Errohandler:

    Debug.Print Err.Number
    If Err.Number = -2147467259 Then
        'MsgBox Err & vbCr & Err.Description

        '################################################
        'HERE CODE FOR FOLDERS "SHOW IN CONVERSATIONS"

        Dim colCB, objCBB
        Set colCB = NewExpl.CommandBars

        If Not NewExpl Is Nothing Then
            If NewExpl.CommandBars.GetPressedMso("ShowInConversations") Then
                ShowInConversations = True
                MsgBox "please press [enter] on next dialog box"
                NewExpl.CommandBars.ExecuteMso ("ShowInConversations")
                'SendKeys "{enter}"
            End If

        End If
        Stop
        Resume
        '################################################
    Else
        MsgBox Err & vbCr & Err.Description
        NewExpl.Display
        NewExpl.WindowState = olMaximized
        Exit Sub
    End If
End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Maybe you can change it via CurrentView object, maybe directly via its xml property. I don't know. However, acccording to MSDN and my own tests with Outlook 2010, the conversation view isn't the problem. Where did you read it is causing the error?
 

oliv-

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I read it on the Error dialog box !

here is my new operational version

Code:
Public Sub GetItemFolderPathAndSwitch()
'---------------------------------------------------------------------------------------
' Procedure : GetItemFolderPathAndSwitch
' Author    : Michael BAUER, improved by OLiv
' Date      : 23/06/2015
' Purpose   :
'---------------------------------------------------------------------------------------
'
    Dim obj As Object
    Dim F As Outlook.MAPIFolder
    Dim NewExpl As Explorer
    Dim Msg$
    Dim ShowInConversations As Boolean
    Set obj = Application.ActiveWindow
    If TypeOf obj Is Outlook.Inspector Then
        Set obj = obj.CurrentItem
    Else
        Set obj = obj.Selection(1)
    End If
    Set F = obj.Parent
    Msg = "The path is: " & F.FolderPath & vbCrLf
    Msg = Msg & "Switch to the folder?"
    If MsgBox(Msg, vbYesNo) = vbYes Then
        Set NewExpl = Application.Explorers.add(F, olFolderDisplayFolderOnly)
        On Error GoTo ErrorHandler
        NewExpl.AddToSelection obj
        NewExpl.ShowPane olPreview, False
        NewExpl.ShowPane olToDoBar, False
        NewExpl.Display
        NewExpl.WindowState = olMaximized
    End If

    Exit Sub
ErrorHandler:

    Debug.Print Err.Number
    If Err.Number = -2147467259 Then
        'MsgBox Err & vbCr & Err.Description

        '################################################
        'HERE CODE FOR FOLDERS "SHOW IN CONVERSATIONS"

        Dim objView As View, objViewTemp As View

        If NewExpl.CommandBars.GetPressedMso("ShowInConversations") Then
            ShowInConversations = True

            Set objView = NewExpl.CurrentFolder.CurrentView
            objView_Mem = objView.Name
            On Error Resume Next
            Set objViewTemp = objView.Parent("tmpNoConversation")
            If objViewTemp Is Nothing Then
                Set objViewTemp = objView.Copy("tmpNoConversation", olViewSaveOptionThisFolderOnlyMe)
                objViewTemp.XML = Replace(objView.XML, "<upgradetoconv>1</upgradetoconv>", "", 1, , vbTextCompare)
               
                objViewTemp.Save
            End If
            On Error GoTo 0
            objViewTemp.Reset
            objViewTemp.Apply
            DoEvents
        End If

        NewExpl.Activate
        DoEvents
        NewExpl.ClearSelection
        NewExpl.AddToSelection obj
        NewExpl.Display
        NewExpl.WindowState = olMaximized

        If ShowInConversations Then
         Set objView = NewExpl.CurrentFolder.Views(objView_Mem)
            objView.Reset
            objView.Apply
            objViewTemp.Delete
        End If

        '################################################
    Else
        MsgBox Err & vbCr & Err.Description
        NewExpl.Display
        NewExpl.WindowState = olMaximized
        Exit Sub
    End If
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Select the position of an attached file in a HTML mailitem Outlook VBA and Custom Forms 1
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
R Add 'Company' to Select Names Form Using Outlook 1
B Select / activate first email item in the searched query Using Outlook 1
A Multi-select Listbox Outlook VBA and Custom Forms 6
H Select Specific Account When Sending Email, Based on Current Folder Outlook VBA and Custom Forms 1
S Display PF contact folder items to select contact to link to appointment Outlook VBA and Custom Forms 1
N Auto-complete - block select emails Using Outlook 3
N Select Appointment subject line from combobox or list Outlook VBA and Custom Forms 1
G How to Copy Multi Select Listbox Data to Appointment Outlook VBA and Custom Forms 3
N Select a folder in a user account Outlook VBA and Custom Forms 2
Diane Poremsky Select from a List of Subjects before Sending a Message New Slipstick.com Articles 0
Diane Poremsky Select Multiple Calendars in Outlook New Slipstick.com Articles 0
P Select image in contact notes field and save as jpg Outlook VBA and Custom Forms 6
N Select Existing BCM Business Contact in C# application Using Outlook 0
nathandavies Creating a Select Case for a directory of folders Outlook VBA and Custom Forms 1
B What is the best way to use Outlook address book to select customer and then open Excel Outlook VBA and Custom Forms 22
C Outlook 2007 Select Names Default columns Using Outlook 3
R Can BCM monitor and select specific emails and use content info to update the client's record? BCM (Business Contact Manager) 1
R Cannot select iCloud calendar Using Outlook 5
H Select one of Contact-Mailadesses to Export > Excel or Winword Outlook VBA and Custom Forms 2
G Select Outlook account for BCM? BCM (Business Contact Manager) 2
Z Manual archive of select folders Using Outlook 1
R How to modify Outlook Select Rooms form columns Using Outlook 1
Z bulk add categories / with fixed colours / select multiple categories on a not Using Outlook 1
C Outlook editing won't select just one word Using Outlook 1
I Address book contacts not listed in "Select Names:Contacts" window Using Outlook 2
Y Outlook 2010 Select and reply to multiple messages at one time Using Outlook 0
Y Outlook 2010 Select and reply to multiple messages at one time Using Outlook 2
D Contacts as default in Select Names dialog Using Outlook 1
D How to select different account when sending emails from Outlook 2003 Using Outlook 3
E Outlook 2010 calendar print - select begin-end weeks for month print but Preview and print show ful Using Outlook 2
R Select contacts and print labels for selected contacts from complete contact list in Outlook. Using Outlook 1
F Why do messages only arrive when I select the server's folder? Using Outlook 3
P Sharing Outlook contacts so users can select as an address book for email. Using Outlook 1
B Do not allow / Show to select "Tentative" option in Responce Using Outlook 1
H Exchange Server 2007 strips messages when clients select add item in a new Message Using Outlook 10
R Cannot select items from Outlook 2007 Menu bars Using Outlook 1
D Outlook 2010 crashes when I select new message, reply, forward or send as attachment Using Outlook 3
M Not able to select my contacts list for my address book Using Outlook 7
L Rule to select incoming messages by contact category Using Outlook 11
C Select folder to file send emails Using Outlook 1
G MS Exchange ActiveSync 2007 Denying Select Devices Exchange Server Administration 2
D Select categories to print Using Outlook 1
C Error when trying to select the Email Auto link option Using Outlook 2
N Not able to select the details of a head office synced contact Exchange Server Administration 4
Z "Select Names: Contacts" Menu displays contacts in different ways Using Outlook 6
G Select DAG for Express full backup ofr copy backups Exchange Server Administration 1
S Outlook 2003: For select messages only, would like replies automatically sent to 2 separate addresses. Using Outlook 4
B How do I select who the email is coming from and who replies go to for a mail merge? Using Outlook 1
Similar threads


















































Top