【问题标题】:Run Script to Append Subject and Body of Email运行脚本以附加电子邮件的主题和正文
【发布时间】:2015-08-30 08:33:11
【问题描述】:

我正在 [尝试] 学习如何在 Outlook 中编写脚本,以便在电子邮件中设置特定类别时:

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

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

我对找到的样本真的没有任何运气。

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

【问题讨论】:

标签: vba outlook exchange-server outlook-2013


【解决方案1】:
  1. 用“PROJ=5”附加主题

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

Example

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

Helpful article in 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

【讨论】:

  • 谢谢,但这并没有解决我的问题。我应该提供一些我在原始帖子中尝试过的东西。这些只是给了我无法工作的相同样本。
  • @thunderchld 你运行的是什么版本的outlook?
  • 我正在使用 Outlook 2013
  • @thunderchld 我希望有 Outlook 2013 的人能提供帮助,我已经用我在 2010 Outlook 上测试过的完整代码更新了我的答案,如果没有的话,我相信它会在 2013 年工作,然后告诉我。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-10
  • 2015-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多