我[尝试]学习如何在 Outlook 中编写一个脚本,当在电子邮件上设置特定类别时:
我的目标是用类别标记电子邮件并将电子邮件转发到我们的票务系统。
我对找到的样本并没有什么运气。
我尝试过的示例(URL)(复制代码并更新相关字段):
- 在主题中添加“PROJ=5”
MailItem.Subject Property
- 返回指示 Outlook 项目的字符串。读/写。
Item.Subject = "PROJ=5" & Item.Subject
- 在正文中添加大约 10 行文本
示例
Dim olBody As String
olBody = "<HTML><BODY><P>Append the Body with about 10 lines of text</P>" & vbNewLine & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P></HTML></BODY>" & vbNewLine
olForward.HTMLBody = olBody & vbCrLf & olForward.HTMLBody
- 发送/转发电子邮件
示例
'//
Set olForward = Item.Forward
'// add Recipent
olForward.Recipients.Add "[email protected]"
'// Send or your use .Dispaly
olForward.Send
运行脚本规则
要使用规则向导,您的宏必须具有预期的参数:
示例
Public Sub ItemForward(Item As Outlook.MailItem)
End Sub
在 Outlook 2010 VBA 上完成代码测试:
请确保您的参考文献设置为运行操作脚本(工具>参考文献)
Option Explicit
'// Run Action Script
Public Sub ItemForward(Item As Outlook.MailItem)
Dim olApp As Outlook.Application
Dim olForward As MailItem
Dim olBody As String
Set olApp = CreateObject("Outlook.Application")
'// Append the Subject
Item.Subject = "PROJ=5 " & Item.Subject
Item.Save
Set olForward = Item.Forward
'// add Recipent
olForward.Recipients.Add "[email protected]"
olBody = "<HTML><BODY><P>Append the Body with about 10 lines of text</P>" & vbNewLine & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P>" & vbNewLine & _
"<P>Append the Body with about 10 lines of text</P></HTML></BODY>" & vbNewLine
'// Forward Email
olForward.HTMLBody = olBody & vbCrLf & olForward.HTMLBody
'// Send or your use .Dispaly
olForward.Send
Set olApp = Nothing
Set olForward = Nothing
End Sub