+ Reply to Thread
Results 1 to 9 of 9

Outlook VBA remove specific email address from ReplyAll message

Hybrid View

good4un2u Outlook VBA remove specific... 03-04-2015, 03:48 PM
good4un2u Re: Outlook VBA remove... 03-06-2015, 10:21 PM
TMS Re: Outlook VBA remove... 03-07-2015, 12:10 AM
good4un2u Re: Outlook VBA remove... 03-09-2015, 08:38 AM
good4un2u Re: Outlook VBA remove... 03-15-2015, 12:10 PM
good4un2u Re: Outlook VBA remove... 03-16-2015, 06:37 PM
little.duck.rabbit Re: Outlook VBA remove... 06-07-2015, 03:04 AM
good4un2u Re: Outlook VBA remove... 06-09-2015, 10:36 AM
little.duck.rabbit Re: Outlook VBA remove... 06-07-2015, 03:06 AM
  1. #1
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Question Outlook VBA remove specific email address from ReplyAll message

    I am trying to remove a specific email address from the replyall using VBA macro. The following is my code

    Public Sub Response(Item As Outlook.MailItem)
    
    'Create an object to contain the original email
    Dim origEmail As Outlook.MailItem
    
    'Retain the original email
    Set origEmail = Item
    
    'Reply to everyone
    Set myResponse = origEmail.ReplyAll
    
    With myResponse
            'Remove the sender from the array of recipients
            .Recipients.Remove (1)
    
             'Remove specific email address
             For i = .Recipients.Count To 1 Step -1
            If LCase(.Recipients.Item(i).Address) = "junior@yahoo.com" Then
            .Recipients.Remove i
            End If
            Next
    
    
            'Add the the messsage
            
            'Attach the original e-mail
            .Attachments.Add origEmail
                        
            'Send the message
            .Send
    End With
        
    'Reset everything
    Set myResponse = Nothing
    Set origEmail = Nothing
    End Sub
    Any help would be appreciated why it doesn't remove the specific email address.
    Last edited by good4un2u; 03-04-2015 at 05:07 PM.

  2. #2
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Re: Outlook VBA remove specific email address from ReplyAll message

    Everything works except the removal of the specific address. Any help would be appreciated.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,115

    Re: Outlook VBA remove specific email address from ReplyAll message

    Looks like it should be:
            .Recipients.Item(i).Remove
    And/or:
            .Recipients.Item(1).Remove


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Re: Outlook VBA remove specific email address from ReplyAll message

    Thanks for the suggestion. I changed it and it still doesn't remove the specific email address. It isn't always in the same position in the array which is why I need to be able to search for the specific email address.

  5. #5
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Re: Outlook VBA remove specific email address from ReplyAll message

    Do you think this code would work if I change it from

     'Remove specific email address
             For i = .Recipients.Count To 1 Step -1
            If LCase(.Recipients.Item(i).Address) = "junior@yahoo.com" Then
            .Recipients.Remove i
            End If
            Next
    To
     'Remove specific email address
             For i = .Recipients.Count To 1 Step -1
            If StrComp(.Recipients.Item(i).Address, "junior@yahoo.com", vbTextCompare) = True Then
            .Recipients.Item(i).Remove
            Next i

  6. #6
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Re: Outlook VBA remove specific email address from ReplyAll message

    I have finally solved this. Here is the code that worked for me.

    Public Sub Response(Item As Outlook.MailItem)
    
    'Create an object to contain the original email
    Dim origEmail As Outlook.MailItem
    
    'Retain the original email
    Set origEmail = Item
    
    'Reply to everyone
    Set myResponse = origEmail.ReplyAll
    
    With myResponse
            'Remove the sender from the array of recipients
            .Recipients.Remove (1)
    
             'Remove specific email address from the array of recipients
             For i = Item.Recipients.Count To 1 Step -1
            If StrComp(.Recipients.Item(i).Address, "junior@yahoo.com", vbTextCompare) = 0 Then
            .Recipients.Remove (i)
            End If
            Next i
    
    
            'Add the the messsage
            
            'Attach the original e-mail
            .Attachments.Add origEmail
                        
            'Send the message
            .Send
    End With
        
    'Reset everything
    Set myResponse = Nothing
    Set origEmail = Nothing
    End Sub
    Last edited by good4un2u; 03-16-2015 at 06:40 PM.

  7. #7
    Registered User
    Join Date
    06-07-2015
    Location
    singapore
    MS-Off Ver
    2013
    Posts
    2

    Re: Outlook VBA remove specific email address from ReplyAll message

    Hi good4un2u,

    does this vba code working? i have try my end and it did not work under outlook 2013
    can advice for it?

  8. #8
    Registered User
    Join Date
    03-04-2015
    Location
    Lucas, IA
    MS-Off Ver
    2010
    Posts
    9

    Re: Outlook VBA remove specific email address from ReplyAll message

    Hello little.duck.rabbit,
    This code worked for me in Outlook 2010. What do you mean by "it doesn't work" What is it not doing or what is it doing to make it not work for you?

  9. #9
    Registered User
    Join Date
    06-07-2015
    Location
    singapore
    MS-Off Ver
    2013
    Posts
    2

    Re: Outlook VBA remove specific email address from ReplyAll message

    Hi good4un2u,

    does this vba code working? i have try my end and it did not work under outlook 2013
    can advice for it?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need Help with HTMLBody. Hyperlink email address and web address in body message VBA
    By Christopher Val in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2015, 04:39 PM
  2. Using macro to find email address in address book of Outlook
    By danfullwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2014, 06:48 AM
  3. Outlook: How to set a specific group of members/email address
    By Ericng in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 07-10-2013, 05:07 AM
  4. Macro to PDF a sheet in workbook and email (outlook) to an email address in a cell
    By paul_sykes00 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-17-2012, 12:54 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1