Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Remove recipients (Outlook XP)

    I have a piece of code which runs when Reply to All is clicked. It is meant to warn the user and ask if All recipients are to remain. If not, all but recipient 1 should be removed.

    But this is not happening. No recipient name is removed. I added a line of code to display each recipient as the loop iterates, and the names display as expected, last first, and excluding recipient one. Can anyone suggest what might be awry in this snippet of code? Since the MsgBox displays the names correctly, it would appear that the objects are all correctly in place, namely msg.

    Thanks, Richard Barrett

    Code:
    For i = count To 2 Step -1
    msg.Recipients.Remove
    MsgBox msg.Recipients(i)
    Next

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    This code has a couple of problems - can you post the entire sub?
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    John, I was not using the Save method, and I've added it (perhaps in the wrong spot), but with no change in my results. The MsgBox, as I mentioned, displays the name as expected. The .Remove method has no effect, even with the addition of the .Save method. (I've tried this in several locations.)

    Any ideas looking at the complete code below?

    Option Explicit
    Dim WithEvents colInsp As Outlook.Inspectors

    Private Sub Application_Startup()
    Set colInsp = Application.Inspectors
    End Sub

    Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
    Dim msg As Outlook.MailItem
    Dim mymsg As String
    Dim myResult As Integer
    Dim count As Integer
    Dim i As Integer
    On Error Resume Next

    If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
    Set msg = Inspector.CurrentItem
    ' check if new item
    If msg.Size = 0 Then
    ' check if replyall
    If msg.Recipients.count > 1 Then
    mymsg = "Do you really want to reply to all original recipients?"
    myResult = MsgBox(mymsg, vbYesNo, "REPLY WARNING")
    If myResult = vbNo Then
    ' remove all recipients except the first one
    count = msg.Recipients.count
    For i = count To 2 Step -1
    MsgBox msg.Recipients(i)
    msg.Recipients.Remove i
    Next
    msg.Save ' Correct placement??
    End If
    End If
    End If
    Set msg = Nothing
    End If
    End Sub

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    Perhaps this will help:

    Sub RemoveUnresolved()
    Dim i As Integer
    With ActiveInspector.CurrentItem ' where the currently open itm is the message draft
    .Recipients.ResolveAll
    For i = .Recipients.Count To 1 Step -1
    If Not .Recipients(i).Resolved Then .Recipients.Remove i
    Next i
    End With
    End Sub

    Note the non standard syntax for the Then ... Remove line - I thought '.Recipients(i).Remove' would work, but it doesn't, don't know why
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    Can you explain "Resolved" and ResolveAll? What is the purpose?

    Thanks.

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    Yes, you would expect that the Index would appear immediately after Recipients. Outlook seems to be unique in this regard, at least with the Remove method.

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    Richard, this is working for me though it's stripped down from what you want:

    Sub AllButOne()
    Dim i As Integer
    With ActiveInspector.CurrentItem
    If .Recipients.Count > 1 Then
    If MsgBox("Do you really want to reply to all original recipients?", _
    vbYesNo, "REPLY WARNING") = vbNo Then
    ' remove all recipients except the first one
    For i = .Recipients.Count To 2 Step -1
    Debug.Print .Recipients(i)
    .Recipients.Remove i
    Next
    .Save
    End If
    End If
    End With
    End Sub

    BTW, my other post doesn't do what you wanted to. Could your problem be the event handle grabbing the Inspector? Could you do this through the Item_Send Event instead?
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    They are a tangent from what you are looking for - a technique for handling recipients who don't resolve to a known address - but they aren't what you need for your purpose ... assuming anyone using Reply to All will be replying to resolved or resolveable addresses.

    (Lately I have been on this annoying trend of misunderstanding questions and giving off-track answers!)
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    This works fine as a separate macro. But when this code is run in _NewInspector, it does not behave correctly. The code does execute, and the recipients display in a message box, but they are not removed. Once my code runs, however, AllButOne does NOT remove anything because the recipient count is 1... even though all three names (I had three names in my test message) still display in the To field.

    What can you tell me about the .Save method? Did I place it correctly? That may be a factor here, although I've trying putting it in a number of locations.

  10. #10
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    I just noticed something very interesting. My event handler is working as expected, and I don't think there's something better suited.

    After running my original code (_NewInspector event), the several names remain. But if I run a little macro to display Recipients.Count, it shows 1. And when I Send the message, it goes only to the first recipient.... despite the fact the all of the names remained in the To: field.

    Any ideas about this? It looks more like a display issue. Is there a way to force a screen refresh or other update?

  11. #11
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    Try:

    msg.Close olSave ' in place of .Save
    msg.Display
    -John ... I float in liquid gardens
    UTC -7ąDS

  12. #12
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    This does not help. I placed these two lines of code immediately after Next. Is there a better location?

  13. #13
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Remove recipients (Outlook XP)

    They should work there. If these are HTML messages, there may be a rendering lag in the display of the message. Another thing you could try is:

    msg.Recipients.ResolveAll

    before the .Save or .Close, to see if forces a redraw. If the code is doing what you want and the display is the only problem, is it crucial?
    -John ... I float in liquid gardens
    UTC -7ąDS

  14. #14
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove recipients (Outlook XP)

    <P ID="edit" class=small>(Edited by jscher2000 on 24-Jul-06 17:08. Fixed indenting for readability.)</P>This is a m

  15. #15
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Remove recipients (Outlook XP)

    I didn't have much luck with this. The ReplyAll event doesn't fire. Don't I need something that will run when Outlook starts to Set myOlInsp? I tried setting with the following:

    Private Sub application_startup()
    Set myOLInsp = Application.Inspectors
    End Sub

    But that didn't seem to help. If I run that Startup Sub, ReplyToAll then tries to run the NewInspector event. But there's an error at myOLMI.myOLMI = Inspector.CurrentItem. I changed that to myOLInsp.myOLMI, and an error than announces that an object is required.

    I had already tried the code you suggest in the final procedure (using While instead of the reverse-count For), and that "worked" as far as reducing Recipients.Count to 1... but the on-screen display still showed all original names. When Sen<!t>[, the reply went to only the first Recipient.

    Do you have any insight into what I've done incorrectly?

    Thanks,
    Richard

Page 1 of 2 12 LastLast

Posting Permissions

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