繁体   English   中英

运行脚本以附加电子邮件的主题和正文

[英]Run Script to Append Subject and Body of Email

我 [试图] 学习如何在 Outlook 中编写一个脚本,当在电子邮件上设置某个类别时:

  1. 用“PROJ=5”附加主题
  2. 在正文中添加大约 10 行文本
  3. 发电子邮件。

我的目标是用类别标记电子邮件并将电子邮件转发到我们的票务系统。

我对我找到的样本并不抱有任何运气。

我尝试过的示例(URL)(复制代码并更新相关字段):

  1. 用“PROJ=5”附加主题

MailItem.Subject Property返回一个字符串,指示 Outlook 项目。 读/写。

例子

Item.Subject = "PROJ=5" & Item.Subject
  1. 在正文中添加大约 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
  1. 发送/转发电子邮件

例子

'// 
Set olForward = Item.Forward
'// add Recipent
olForward.Recipients.Add "email@domain.com"
'// Send or your use .Dispaly 
olForward.Send

运行脚本规则

要使用Rule Wizard ,您的宏必须具有预期的参数:

例子

Public Sub ItemForward(Item As Outlook.MailItem)

End Sub

MSDN Outlook 2010 VBA 中的有用文章

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 "Test@mail.com"


    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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM