2014-10-29 48 views
0

當在所有Outlook項目中搜索項目時,它顯示找到的消息/項目。部分搜索結果項目包括消息所在的文件夾。我試圖打開項目所在的父文件夾的新窗口,然後在新窗口中突出顯示該消息。下面的代碼打開文件夾,但我不知道如何找到並選擇該項目。打開所選消息文件夾並選擇消息

'Opens folder in new windows of current messages folder location 
Public Sub OpenFolderPath() 
    Dim obj As Object 
    Dim objOLApp As Outlook.Application 
    Dim objExp As Outlook.Explorer 
    Dim F As Outlook.MAPIFolder 
    Dim Msg$ 
    Dim SelMsg As MailItem 
    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.Name & vbCrLf 
    Msg = Msg & "Switch to the folder?" 
    If MsgBox(Msg, vbYesNo) = vbYes Then 
    Set objExp = Application.Explorers.Add(F, olFolderDisplayNormal) 
    objExp.Activate 
    End If 
' The following does not work 
    For Each SelMsg In objExp.CurrentFolder.Items 
    If obj.EntryID = SelMsg.EntryID Then 
     MsgBox SelMsg.EntryID 
' What to put here to select the found item. 
    End If 
    Next 
End Sub 

回答

0

我想你會發現Outlook對象模型不包括這個。

我建議設置未讀=真

0
'Opens folder in new windows of current messages folder location 
Public Sub OpenFolderPath() 
    Dim obj As Object 
    Dim objOLApp As Outlook.Application 
    Dim objExp As Outlook.Explorer 
    Dim F As Outlook.MAPIFolder 
    Dim Msg$ 
    Dim SelMsg As MailItem 
    Dim i as Long 
    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.Name & vbCrLf 
    Msg = Msg & "Switch to the folder?" 
    If MsgBox(Msg, vbYesNo) = vbYes Then 
    Set objExp = Application.Explorers.Add(F, olFolderDisplayNormal) 
    objExp.Activate 
    End If 
' The following does not work 
    i = 1 
    For Each SelMsg In objExp.CurrentFolder.Items 
    If obj.EntryID = SelMsg.EntryID Then 
     MsgBox objExp.CurrentFolder.Items.Item(i) 
' What to put here to select the found item. 
    End If 
    i = i + 1 
    Next 
End Sub 
+0

請試試這個代碼,看看它是否工作,你想要的東西... – user4192334 2014-10-29 02:26:36

+0

請解釋什麼答案的變化以及如何地址的OP如此關注我不必盯着它看看有什麼不同。 – Matt 2014-10-29 02:47:19

+0

更改包括添加新變量i,初始化i = 1,i = i + 1和objExp.CurrentFolder.Items.Item(i),當obj.EntryID與SelMsg.EntryID匹配時。 – user4192334 2014-10-29 02:58:29