如何在不覆盖整个正文消息的情况下回复电子邮件?
How to Reply to an Email without Overwriting the whole Body Message?
我编写了一个程序,用于在 Outlook 中查找特定邮件。然后打开邮件的回复部分并更改收件人、抄送收件人并添加来自 excel sheet 的正文消息。
当我运行这个程序时,它会覆盖整个消息体,包括之前的消息。
如何在不覆盖之前的消息的情况下添加正文消息?
Sub ReplyEmailV1(sMailBody As String, sMailTo As String, sMailCC As String)
' initialize variables
Dim olApp As Outlook.Application
Dim olNameSpace As namespace
Dim olFolder As MAPIFolder
Dim olMail As Outlook.MailItem
Dim iCountEmail As Integer
' set up Outlook Application
Set olApp = New Outlook.Application
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
iCountEmail = 1
'*************************************
'Loop for each folder items in Outlook
'*************************************
For Each olMail In olFolder.Items
'*************************************
'Search for the codename in the searchbar of MS Outlook
'*************************************
If InStr(olMail.body, "bcqweqw") <> 0 Then
With olMail.Reply
'*************************************
'Get the specified email
'Open the specified email
'Open reply
'*************************************
.Display
'*************************************
'Change To recipient
'*************************************
.To = sMailTo
'*************************************
'Change CC recipient
'*************************************
.CC = sMailCC
'*************************************
'Add the body message
'*************************************
.body = sMailBody
'*************************************
'Send the reply message
'*************************************
.Save
.Send
'*************************************
'Close the specified Email
'*************************************
'*************************************
'Increment email count
'*************************************
iCountEmail = iCountEmail + 1
End With
End If
'*************************************
'Loop to the next email found if codename is found
'*************************************
Next olMail
End Sub
Sub ReplyMultipleEmails()
'Dim iRow As Integer
'iRow = 2
Call ReplyEmailV1(Sheets("Template").Cells(1, 1), Sheets("Data").Cells(2, 7), Sheets("Data").Cells(2, 7))
'iRow = iRow + 1
End Sub
我尝试了这个并且成功了:
.body = sMailBody & vbLF & .body
我编写了一个程序,用于在 Outlook 中查找特定邮件。然后打开邮件的回复部分并更改收件人、抄送收件人并添加来自 excel sheet 的正文消息。
当我运行这个程序时,它会覆盖整个消息体,包括之前的消息。
如何在不覆盖之前的消息的情况下添加正文消息?
Sub ReplyEmailV1(sMailBody As String, sMailTo As String, sMailCC As String)
' initialize variables
Dim olApp As Outlook.Application
Dim olNameSpace As namespace
Dim olFolder As MAPIFolder
Dim olMail As Outlook.MailItem
Dim iCountEmail As Integer
' set up Outlook Application
Set olApp = New Outlook.Application
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
iCountEmail = 1
'*************************************
'Loop for each folder items in Outlook
'*************************************
For Each olMail In olFolder.Items
'*************************************
'Search for the codename in the searchbar of MS Outlook
'*************************************
If InStr(olMail.body, "bcqweqw") <> 0 Then
With olMail.Reply
'*************************************
'Get the specified email
'Open the specified email
'Open reply
'*************************************
.Display
'*************************************
'Change To recipient
'*************************************
.To = sMailTo
'*************************************
'Change CC recipient
'*************************************
.CC = sMailCC
'*************************************
'Add the body message
'*************************************
.body = sMailBody
'*************************************
'Send the reply message
'*************************************
.Save
.Send
'*************************************
'Close the specified Email
'*************************************
'*************************************
'Increment email count
'*************************************
iCountEmail = iCountEmail + 1
End With
End If
'*************************************
'Loop to the next email found if codename is found
'*************************************
Next olMail
End Sub
Sub ReplyMultipleEmails()
'Dim iRow As Integer
'iRow = 2
Call ReplyEmailV1(Sheets("Template").Cells(1, 1), Sheets("Data").Cells(2, 7), Sheets("Data").Cells(2, 7))
'iRow = iRow + 1
End Sub
我尝试了这个并且成功了:
.body = sMailBody & vbLF & .body