簡體   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