在Outlook中显示MailItem的用户定义属性

时间:2018-01-02 19:34:59

标签: vba outlook outlook-vba

我试图在Outlook中向电子邮件添加备注时添加便利。

我的计划是采用我当前的程序,它将备注添加到所选的电子邮件(作为附件),并让它调用一个程序,在UserProperty对象上设置MailItem通过在我的电子邮件列表视图中添加自定义列,我可以轻松查看哪些电子邮件附有说明。

从互联网上搜索我已经拼凑了以下内容。

Option Explicit

Public Sub MarkHasNote()
    Dim Selection As Outlook.Selection
    Dim UserDefinedFieldName As String
    Dim objProperty As Outlook.UserProperty
    Dim objItem As MailItem

    UserDefinedFieldName = "Note"
    Set objItem = GetCurrentItem()
    Set objProperty = objItem.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olYesNo, olFormatYesNoIcon)
    objProperty.Value = True
End Sub

Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application

    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select

    Set objApp = Nothing
End Function

我设置了断点并检查了UserProperties的{​​{1}}。我看到细节在那里,值设置为" True" 。但是,电子邮件不会在Outlook电子邮件窗格的"注意" 列中显示“是/否”图标。

当我将列添加到视图中时,如何让Outlook在电子邮件窗格中显示我的用户定义属性值?

1 个答案:

答案 0 :(得分:1)

选择需要保存。 Inspector项目会提示进行保存。

Private Sub MarkHasNote_DisplayTest()

    ' Add the UserProperty column with Field Chooser
    ' You can view the value toggling when you run through the code

    Dim Selection As Selection
    Dim UserDefinedFieldName As String
    Dim objProperty As UserProperty
    Dim objItem As mailItem

    UserDefinedFieldName = "NoteTest"
    Set objItem = GetCurrentItem()
    Set objProperty = objItem.UserProperties.Add(UserDefinedFieldName, Outlook.OlUserPropertyType.olYesNo, olFormatYesNoIcon)

    objProperty.Value = Not objProperty.Value

    ' Required for an explorer selection
    objItem.Save

    ' For an inspector item there would be a prompt to save
    '  if not already done in the code

End Sub