VBA электронной почте ответ - текст не добавляет

Обновить

April 2019

Просмотры

87 раз

1

Я сочинительство макрос, который находит по электронной почте и ответы на него. Проблема заключается в том, что текст, который я хочу ответить не добавляет. Не могли бы вы сказать мне, что я делаю неправильно?

 Sub Test()

 Dim olApp As Object
 Dim olNs As Object
 Dim Fldr As Object
 Dim i As Long

 Set olApp = CreateObject("Outlook.Application")
 Set olNs = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test")

i = 1

For Each olMail In olNs.Items
If InStr(olMail.Subject, "kanapka") <> 0 Then

    With olMail.ReplyAll

    .CC = "[email protected]"
    .Body = "Dear All," _ 
    & vbCrLf & "aaaaaa" 'these two lines should add
    olMail.Reply.Display

    End With


i = i + 1

End If


Next olMail

End Sub

1 ответы

0

Try adding this to your code:

For Each olMail In olNs.Items
    If InStr(olMail.Subject, "testme") <> 0 Then
        Set oReply = olMail.Reply
        Set oRecip = oReply.Recipients.Add("[email protected]")
        oRecip.Type = olCC
        oReply.HTMLBody = "Thank you!!!" & oReply.HTMLBody
        oReply.Display
        Stop ' - remove this once you try the code.
    End If
Next olMail

As you see, you have to declare oReply and oRecip as Objects, but these two make your life really easier. In order to add some text to the answer, simply increment the body this way:

oReply.HTMLBody = "Thank you!!!" & oReply.HTMLBody

I have also included a Stop in your code, to make sure that it does not display plenty of emails.