Outlook宏 - 使用模板回复发件人

时间:2016-07-05 09:49:50

标签: vba templates outlook macros reply

我正在尝试创建一个宏,该宏将使用共享模板回复所选电子邮件的发件人。

目前我有两个单独的宏。

  1. 将回复发件人并插入他们的地址。
  2. 将使用模板回复(但不会插入发件人地址)。
  3. 我想知道是否有可能将两者结合起来实现我的目标? 因此,当您运行宏时,它会回复带有模板的电子邮件,并填写原始发件人的地址和主题?

    我对VBA的了解非常有限,所以我不确定它是否/如何可能。这就是我所拥有的。

    1:

    Public Sub AccountSelection()
    Dim oAccount As Outlook.Account
    Dim strAccount As String
    Dim olNS As Outlook.NameSpace
    Dim objMsg, oMail As MailItem
    
    Set olNS = Application.GetNamespace("MAPI")
    Set objMsg = ActiveExplorer.Selection.Item(1).Reply
    
    If TypeName(ActiveExplorer.Selection.Item(1)) = "MailItem" Then
     Set oMail = ActiveExplorer.Selection.Item(1)
    
     On Error Resume Next
    
    For Each Recipient In oMail.Recipients
     strRecip = Recipient.Address & ";" & strRecip
    Next Recipient
    
    If InStr(strRecip, "alias@domain1.com") = 1 Then
    strAccount = "alias@domain1.com"
    Else
    End If
    
    For Each oAccount In Application.Session.Accounts
      If oAccount.DisplayName = strAccount Then
         objMsg.SendUsingAccount = oAccount
    
           Else
    
      End If
    Next
    
      objMsg.Display
    
    Else
    
    End If
    
    Set objMsg = Nothing
    Set olNS = Nothing
    End Sub
    

    2

    Sub TacReply()
    Dim origEmail As MailItem
    Dim replyEmail As MailItem
    Set origEmail = Application.ActiveExplorer.Selection(1)
    Set replyEmail = Application.CreateItemFromTemplate("S:\Share\TWGeneral.oft")
    replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody
    replyEmail.SentOnBehalfOfName = "email@domain.com"
    replyEmail.Display
    End Sub
    

    任何帮助将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:0)

确定发送回复的名称,不一定是发件人

origEmail.Reply.To

Sub TacReply()

Dim origEmail As mailItem
Dim replyEmail As mailItem

Set origEmail = ActiveExplorer.Selection(1)
Set replyEmail = CreateItemFromTemplate("S:\Share\TWGeneral.oft")

replyEmail.To = origEmail.Reply.To

replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody
replyEmail.SentOnBehalfOfName = "email@domain.com"
replyEmail.Recipients.ResolveAll
replyEmail.Display

Set origEmail = Nothing
Set replyEmail = Nothing

End Sub