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

时间:2015-06-14 22:17:41

标签: vba exchange-server outlook-vba outlook-2013

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

  1. 使用“PROJ = 5”附加主题
  2. 使用约10行文字附加正文
  3. 发送电子邮件。
  4. 我的目标是标记包含类别的电子邮件,并将电子邮件转发至我们的售票系统。

    我找到的样品并不是真的好运。

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

1 个答案:

答案 0 :(得分:0)

  
      
  1. 使用"附加主题PROJ = 5"
  2.   

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

Example

Item.Subject = "PROJ=5" & Item.Subject
  
      
  1. 使用约10行文字附加正文
  2.   

实施例

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. 发送/转发电子邮件
  2.   

实施例

'// 
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

的完整代码测试

请确保您的参考设置为运行操作脚本(工具&gt;参考)

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