我编写了一个在Outlook中查找特定邮件的程序。然后打开邮件的回复部分并更改收件人,CC收件人并添加来自Excel工作表的正文消息。
现在我的问题是当我运行程序时,它会覆盖整个身体信息,包括之前的信息。
VBA是否有一个确切的代码,只需添加正文消息而不覆盖之前的消息?
这是我上面提到的程序的代码:
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
答案 0 :(得分:0)
我试过这个并且有效:
.body = sMailBody & vbLF & .body
另一个问题:
但是,如果我发送另一封回复同一封电子邮件怎么办?
如何自动将另一个正文消息添加到同一个电子邮件中?
你能救我一下吗?非常感谢。