如果主题中有特定单词,如何编写替换主题的VBA方法。此代码将在电子邮件正文中找到某个关键字(与主题关键字不同)。然后,在文本正文中找到关键词之后,它将用13个字符替换主题行。
以下内容已经找到,但未提及如何在电子邮件正文中找到任何内容。我没有得到MAPI参考。
真正感谢任何帮助 提前感谢您的帮助 瑞克
Sub RewriteSubject(MyMail As MailItem)
Dim mailId As String
Dim outlookNS As Outlook.NameSpace
Dim myMailItem As Outlook.MailItem
mailId = MyMail.EntryID
Set outlookNS = Application.GetNamespace("MAPI")
Set myMailItem = outlookNS .GetItemFromID(mailId)
' Do any detection here
mailItem.Subject = "Dept - " & mailItem.Subject
myMailItem.Save
Set mailItem = Nothing
Set outlookNS = Nothing
End Sub
答案 0 :(得分:1)
如果适用于所有新消息,则可以使用以下
Private Sub Application_ItemSend(ByVal Item As Object,Cancel As Boolean)
Dim v As Variant
For Each v In Array("first", "second")
If InStr(1, Item.Subject, v, vbTextCompare) <> 0 Then
SearchForAttachWords = True
End If
Next
If SearchForAttachWords = True Then
Item.Subject = "Whatever subject you want"
End If
End Sub
希望这有帮助。