【发布时间】:2025-12-10 20:50:02
【问题描述】:
我编写了一个脚本,根据主题中的一些首字母、正文中的一些词、发件人……为所有选定的电子邮件分配一个类别...
Public Sub autocategories()
Dim olItem As Object
For Each olItem In Application.ActiveExplorer.Selection
If InStr(1, olItem.Subject, "=SUB1=", vbTextCompare) > 0 Then
olItem.Categories = "SUB1"
ElseIf InStr(1, olItem.Subject, "=SUB2=", vbTextCompare) > 0 Then
olItem.Categories = "SUB2"
ElseIf InStr(1, olItem.Sender, "SEN1", vbTextCompare) > 0 Then
olItem.Categories = "SEN1"
ElseIf InStr(1, olItem.Sender, "SEN2", vbTextCompare) > 0 Then
olItem.Categories = "SEN2"
ElseIf InStr(1, olItem.Body, "BOD1", vbTextCompare) > 0 Then
olItem.Categories = "BOD1"
ElseIf InStr(1, olItem.Body, "BOD2", vbTextCompare) > 0 Then
olItem.Categories = "BOD2"
End If
olItem.Save
Next olItem
Set olItem = Nothing
End Sub
我制作了第二个脚本来自动为所有发送的电子邮件分配一个类别。
Private Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)
With olItem
If InStr(1, olItem.Subject, "=SUB1=", vbTextCompare) > 0 Then
olItem.Categories = "SUB1"
olItem.Save
ElseIf InStr(1, olItem.Subject, "=SUB2=", vbTextCompare) > 0 Then
olItem.Categories = "SUB2"
olItem.Save
ElseIf InStr(1, olItem.Body, "BOD1", vbTextCompare) > 0 Then
olItem.Categories = "BOD1"
olItem.Save
ElseIf InStr(1, olItem.Body, "BOD2", vbTextCompare) > 0 Then
olItem.Categories = "BOD2"
olItem.Save
Else: End If
End With
lbl_Exit:
Exit Sub
End Sub
对于收到的电子邮件:
- 我希望自动完成分配,而不必选择电子邮件并单击宏按钮
- 使用规则不是一个选项,因为它需要更新我公司禁止的密钥注册表。
对于接收和发送的电子邮件:
- 我想识别附件的文件名
- 我试过这个:
ElseIf InStr(1, olItem.Attachemnts, "[NAME1]", vbTextCompare) > 0 Then
olItem.Categories = "[NAME1]"
olItem.Save
【问题讨论】: