VBA回复电子邮件但缺少一些信息

时间:2017-10-14 01:07:36

标签: vba outlook outlook-vba outlook-2013

我已经编写了一个工作代码来回复某种格式的电子邮件,但结果却遗漏了Html正文中最后收到的电子邮件的一些信息(来自,发送,到,cc,主题。我甚至不是确定这是否称为邮件标题)。

如果我点击Outlook 2013默认的“回复”按钮,这些信息将在最后一封电子邮件之前自动生成,而在其上方则是我的回复内容。

那么我应该使用哪个函数来调用这些信息?信息必须出现在我的所有回复中,所以我需要以某种方式解决它。我的代码:

'there is a getsignature function before the code.
Public Sub my_reply()
Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objSelection As Outlook.Selection
Dim objMail As Outlook.mailitem
Dim StrSignature As String


StrSignature = GetSignature("C:\Users\xxx\xxx\Microsoft\Signatures\ABC.htm")


Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
For Each objMsg In objSelection
    If objMsg.Class = olMail Then
       objMsg.Categories = "Category A"

Set myreply = objMsg.Reply
myreply.To = objMsg.SenderEmailAddress
myreply.BCC = "xxx@abc" & " ; " & "xxx@abc" 
myreply.Subject = "XYZ matter" & objMsg.Subject
myreply.Display
myreply.HTMLBody = StrSignature & "<br><br>" & objMsg.HTMLBody


Release:
  Set objMsg = Nothing
  Set oExplorer = Nothing

     End If

    Next

End Sub

先谢谢。

1 个答案:

答案 0 :(得分:1)

ReplyAll应该获得cc。如果你只关心遗失的文字,请忽略这一点。

Set myReply = objMsg.ReplyAll

您正在使用myreply.HTMLBody

覆盖初始objMsg.HTMLBody
myreply.HTMLBody = StrSignature & "<br><br>" & objMsg.HTMLBody

而是附加到最初的myreply.HTMLBody

Option Explicit

Public Sub my_replyAll()

'Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objSelection As Selection

'Dim objMail As Outlook.mailitem
Dim myReply As mailitem

Dim StrSignature As String

StrSignature = GetSignature("C:\Users\xxx\xxx\Microsoft\Signatures\ABC.htm")

' Set objOL = CreateObject("Outlook.Application")
'Set objSelection = objOL.ActiveExplorer.Selection
Set objSelection = ActiveExplorer.Selection

For Each objMsg In objSelection

    If objMsg.Class = olMail Then

        Set myReply = objMsg.ReplyAll

        myReply.To = objMsg.SenderEmailAddress

        myReply.BCC = "xxx@abc" & " ; " & "xxx@abc"

        myReply.Subject = "XYZ matter " & objMsg.Subject

        myReply.Display

        'myReply.HtmlBody = StrSignature & "<br><br>" & objMsg.HtmlBody
        myReply.HtmlBody = StrSignature & "<br><br>" & myReply.HtmlBody

Release:
        Set objMsg = Nothing

    End If

Next

End Sub