Consulting

Results 1 to 3 of 3

Thread: Delete all Recipients fast

  1. #1
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    5
    Location

    Unhappy Delete all Recipients fast

    Hello,
    i have a vba-script to delete all Recipients in order to get very small Emails. We often have emails that go to 50-300 people, therefore the Emails reaches fastly 1Mb or even 9Mb.
    The code is very simple, go thru each Recipient and delete one after another.
    But this way i have 2 Problems:
    - it is very slow --> how can i make it faster, like "remove_all".
    - if i have recipients in "to" and "CC" then the Emails doesnt get that small. I dont know why. How can i fix it?

    Sub DeleteRecipients()
            'Declaration
            Dim myItems, myItem, myRecipients As Object
            Dim myOrt, myTextRemovedBody, myTextRemovedHTMLBody, myTextRemovedSubject As String
            Dim myOlApp As New Outlook.Application
            Dim myOlExp As Outlook.Explorer
            Dim myOlSel As Outlook.Selection
            
            On Error Resume Next
            
            'work on selected items
            Set myOlExp = myOlApp.ActiveExplorer
            Set myOlSel = myOlExp.Selection
            
            'for all items do...
            For Each myItem In myOlSel
                Set myRecipients = myItem.Recipients
                Do Until myRecipients.Count = 0
                        'remove it (use this method in Outlook XP)
                        myRecipients.Remove (1)
                        'remove it (use this method in Outlook 2000)
                        'myRecipients(1).Delete
                Loop
                'save item without recipients
                myItem.Save
            Next 'myItem
    End Sub

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    See if this make any difference.

    For Each myItem In myOlSel 
            myItem.To = ""
            myItem.cc = ""
             'save item without recipients
            myItem.Save 
        Next 'myItem
    No comment on why size is not reduced as much as you expect.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    VBAX Newbie
    Joined
    Mar 2017
    Posts
    5
    Location
    Dear skatonni,
    Thank you very much, the myItem.To = "" works instantly over many Emails.
    When i have another Email with CCs i will give feedback if that worked on the Email size.

Posting Permissions

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