vba - 使用 Outlook VBA 为所有选定的电子邮件添加一个类别
问题描述
我正在尝试使用 VBA 为 Outlook 中选择的每封电子邮件添加一个类别。
问题是下面的代码仅将类别添加到第一封电子邮件。
我正在使用 Outlook 2016。
Public Sub MarkSelectedAsGreenCategory()
Dim olItem As MailItem
Dim newCategory As String
newCategory = "Green category"
Dim i As Integer
For i = 1 To Application.ActiveExplorer.Selection.Count
Set olItem = Application.ActiveExplorer.Selection(i)
AddCategory olItem, newCategory
Set olItem = Nothing
Next
End Sub
Private Sub AddCategory(mailItem As mailItem, newCategory As String)
Dim categories() As String
Dim listSep As String
' Get the current list separator from Windows regional settings
listSep = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Control Panel\International\sList")
' Break the list up into an array
categories = Split(mailItem.categories, listSep)
' Search the array for the new category, and if it is missing, then add it
If UBound(Filter(categories, newCategory)) = -1 Then
ReDim Preserve categories(UBound(categories) + 1)
categories(UBound(categories)) = newCategory
mailItem.categories = Join(categories, listSep)
End If
End Sub
解决方案
对类别的更新ActiveInspector.CurrentItem
将生成保存提示。
对于选择:
olItem.Save
或mailItem.Save
在您方便的时候。
推荐阅读
- ormlite-servicestack - 使用 servicestack ormlite 通过 http 运行查询
- javascript - 如何在 JavaScript 中获得顺风活动断点?
- python - re.search() 不匹配所有预期的字符串
- axon - 用于并行处理的轴突配置
- python - 维护用户会话而不将用户保存在 django 身份验证系统中
- c# - 检查 Windows 窗体中的文本框
- php - 在 wordpress 中替换 amazon associates 链接构建器拍摄代码
- mailkit - MimeKit HtmlBody thread
- validation - 使用 vee validate 验证自定义输入组件
- python - 如何在做 json.dumps 时只保留 ascii 并丢弃非 ascii、nbsp 等