如何仅在Outlook中的公共文件夹中选择邮件项目

时间:2018-12-17 00:58:49

标签: vba outlook

我如何自动在活动的资源管理器的Outlook窗口中仅选择某个公用文件夹(例如mypublicfolder)中的邮件项目?

欢迎提出任何想法。

Dim objApp As Outlook.Application
Set objApp = Application

Dim oItems As Object
If oItems.Class = olMail Then
    ' How to select only mailitems in a mypublicfolder in outlook explorer
End if

Dim oSel As Outlook.Selection
Set oSel = objApp.ActiveExplorer.Selection

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

Application.Session.Folders。(“ TheDelegateMialboxName@YourCompany.com”)。Folders(“ TheFolderName”)

有关更多信息,请参见以下链接:

How to get the MailItems of a specific folder in Outlook

答案 1 :(得分:0)

您可以用自己的代码替换curFldr来引用公用文件夹。

Private Sub SelectMailitems()

    Dim objExp As Explorer
    Dim curFldr As Folder
    Dim itm As Object

    Dim oItems As Object
    Dim oSel As Selection
    Dim i As Long

    Set objExp = ActiveExplorer

    ' Not valid in a conversation view
    objExp.ClearSelection

    Set curFldr = objExp.CurrentFolder
    Set oItems = curFldr.Items

    For Each itm In oItems
        If itm.Class = olmail Then
            objExp.AddToSelection itm
        End If
    Next

    Set oSel = ActiveExplorer.Selection
    Debug.Print "oSel.count: " & oSel.count

    For i = 1 To oSel.count
        Debug.Print oSel(i).Subject
    Next

End Sub