Макрос Outlook: удаление получателя в «Ответить всем» - PullRequest
0 голосов
/ 17 октября 2018

Это сводило меня с ума этим утром.По сути, я пытаюсь написать макрос, который будет «отвечать всем», добавить текст в тему, добавить получателя и удалить получателя.

Sub Reply_All()
    Dim olReply As mailitem
    Dim strSubject As String
    For Each olItem In Application.ActiveExplorer.Selection
    Set olReply = olItem.ReplyAll
    Set olRecip = olReply.Recipients.Add("EmailAddressGoesHere")
    Set olRecip = olReply.Recipients.Remove("EmailAddressGoesHere")
    strSubject = olReply.Subject
        olReply.Subject = "(Added Subject Line Info - ) " & strSubject
        olReply.Display
    Next
End Sub

Все работает, когда я закомментирую строку "Recipients.Remove".

Последние несколько часов я безумно гуглял и не могу понять, как получитьэто работает правильно.

Я заметил, что

Set olRecip = olReply.Recipients.Add("EmailAddressGoesHere")

имеет "Добавить имя как строку"

В то время как

Set olRecip = olReply.Recipients.Remove("EmailAddressGoesHere")

Имеет "Удалить индекс какДлинный "как желтый текст, который появляется, когда вы вводите его в сценарий.

Я чувствую, что должно быть действительно простое решение, о котором я сейчас не думаю.

Ответы [ 3 ]

0 голосов
/ 18 октября 2018

Как отметил Дмитрий, вы можете обратиться к следующему коду:

    Sub Reply_All()
    Dim olReply As MailItem
    Dim strSubject As String
    For Each olItem In Application.ActiveExplorer.Selection
    Set olReply = olItem.ReplyAll
    For Each Address In EmailAddressGoesHere
    olReply.Recipients.Add (Address)
    Next
    For Each Rec In olReply.Recipients
        Rec.Delete
    Next
    strSubject = olReply.Subject
        olReply.Subject = "(Added Subject Line Info - ) " & strSubject
        olReply.Display
    Next
    End Sub

Для получения дополнительной информации, пожалуйста, перейдите по этой ссылке:

удалить получателя из коллекции mail.recipient

0 голосов
/ 18 октября 2018
Option Explicit
' Consider Option Explicit mandatory
' Tools | Options | Editor tab | Require Variable Declaration

Sub Reply_All_RemoveSingleOrMultipleCopiesAddress()

    Dim olItem As Object
    Dim olReply As MailItem

    Dim i As Long

    For Each olItem In ActiveExplorer.Selection

        If olItem.Class = olMail Then

            Set olReply = olItem.ReplyAll

            'olReply.Display

            ' If the address could occur once or multiple times,
            '  start at the end and work backwards
            For i = olReply.Recipients.count To 1 Step -1

                'Debug.Print olReply.Recipients(i).Address

                ' "EmailAddressToBeRemoved" with the quotes as shown
                If LCase(olReply.Recipients(i).Address) = LCase("EmailAddressToBeRemoved") Then
                    olReply.Recipients.remove (i)
                End If

            Next

            olReply.Display

        End If

    Next

End Sub


Sub Reply_All_RemoveSingleAddressReliably()

    Dim olItem As Object
    Dim olReply As MailItem
    Dim recip As recipient

    For Each olItem In ActiveExplorer.Selection

        If olItem.Class = olMail Then

            Set olReply = olItem.ReplyAll

            'olReply.Display

            ' If the address can appear once only,
            '  otherwise use a downward counting loop
            For Each recip In olReply.Recipients

                'Debug.Print recip.Address

                ' "EmailAddressToBeRemoved" with the quotes as shown 
                If LCase(recip.Address) = LCase("EmailAddressToBeRemoved") Then

                    ' Delete not remove
                    recip.Delete

                    ' No need to continue if only one instance of address can occur,
                    '  otherwise you would unreliably delete anyway.
                    ' The address immediately after a deleted address is skipped
                    '  as it moves into the old position of the deleted address.
                    Exit For

                End If

            Next

            olReply.Display

        End If

    Next

End Sub
0 голосов
/ 17 октября 2018

Циклически перебирайте получателей с помощью цикла for от Count до 1, проверьте свойство Recipient.Address.Если оно соответствует значению, которое вы ищете, позвоните Recipients.Remove, передав текущий индекс цикла.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...