![](/img/trans.png)
[英]Late binding compile error: User-defined type not defined referencing Outlook mailitem in Excel VBA
[英]Displaying User Defined Property of MailItem in Outlook
我試圖在 Outlook 中向電子郵件添加備注時增加便利性。
我的計划是采用我當前的程序,將注釋添加到選定的電子郵件(作為附件),並讓它調用一個程序,該程序將在MailItem
對象上設置一個UserProperty
,以便我可以輕松查看哪些電子郵件附加了注釋向我的電子郵件列表視圖添加自定義列。
通過在互聯網上搜索,我拼湊了以下內容。
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
我已經設置了一個斷點並檢查了MailItem
的UserProperties
。 我看到詳細信息在那里並且值設置為"True" 。 但是,該電子郵件不會在 Outlook 電子郵件窗格的“注釋”列中顯示是/否圖標。
當我將列添加到視圖時,如何讓 Outlook 在電子郵件窗格中顯示我的用戶定義的屬性值?
選擇需要保存。 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.