在 Outlook (VBA) 中附加主题标题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/95625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Append Subject Header in Outlook (VBA)
提问by
Basically, we have a rule setup to run a script when a code word is detected in the body of an incoming message. The script will append the current subject header with a word in front. For example, Before: "Test Message", After: "Dept - Test Message". Any ideas?
基本上,当在传入消息的正文中检测到代码字时,我们有一个规则设置来运行脚本。该脚本将在当前主题标题前面附加一个单词。例如,之前:“测试消息”,之后:“部门 - 测试消息”。有任何想法吗?
回答by Matt
Or if you need an entire script:
或者,如果您需要整个脚本:
Do the Run a script with the MailItem as the parameter.
执行以 MailItem 作为参数的运行脚本。
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
With myMailItem
.Subject = "Dept - " & mailItem.Subject
.Save
End With
Set myMailItem = Nothing
Set outlookNS = Nothing
End Sub
回答by Matt
Sub AppendSubject(MyMail As MailItem)
Dim strID As String
Dim mailNS As Outlook.NameSpace
Dim mailItem As Outlook.MailItem
strID = MyMail.EntryID
Set mailNS = Application.GetNamespace("MAPI")
Set mailItem = mailNS.GetItemFromID(strID)
mailItem.Subject = "Dept - " & mailItem.Subject
mailItem.Save
Set mailItem = Nothing
Set mailNS = Nothing
End Sub
Are we missing anything? EDIT: Doh! You already answered our question with a full script... Thanks!
我们错过了什么吗?编辑:哦!您已经用完整的脚本回答了我们的问题……谢谢!
回答by Matt
Not tested:
未测试:
mailItem.Subject = "Dept - " & mailItem.Subject
mailItem.Save