![]() |
Reply/Reply All
VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All
events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Trap the selection change events (Explorer.SelectionChange). For each item
in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Dmitry, as always, thank you for guiding me....
Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
The line
Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Okay, that worked like a champ. I can't believe I missed that. One last bug.
So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
You need to unsubscribe from the event if mailItem!= null.
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Okay, that worked like a champ. I can't believe I missed that. One last bug. So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Sorry Dmitry, but I cannot figure out the best place to put
RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll At first I added it to the SectionChange routine, but that just killed the event, so then I thought I had to add it to the ReplyAll event after it runs, but that did nothing, same error. Sorry for all your time. I appreciate this. "Dmitry Streblechenko" wrote: You need to unsubscribe from the event if mailItem!= null. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Okay, that worked like a champ. I can't believe I missed that. One last bug. So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Did you first check that mailItem is not null? What is your latest code?
Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Sorry Dmitry, but I cannot figure out the best place to put RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll At first I added it to the SectionChange routine, but that just killed the event, so then I thought I had to add it to the ReplyAll event after it runs, but that did nothing, same error. Sorry for all your time. I appreciate this. "Dmitry Streblechenko" wrote: You need to unsubscribe from the event if mailItem!= null. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Okay, that worked like a champ. I can't believe I missed that. One last bug. So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
Have a look:
public class ThisApplication Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Public mailItem As Outlook.MailItem = Nothing Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection mailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next If (mailItem IsNot Nothing) Then RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) 'blah blah blah End Sub End Class "Dmitry Streblechenko" wrote: Did you first check that mailItem is not null? What is your latest code? Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Sorry Dmitry, but I cannot figure out the best place to put RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll At first I added it to the SectionChange routine, but that just killed the event, so then I thought I had to add it to the ReplyAll event after it runs, but that did nothing, same error. Sorry for all your time. I appreciate this. "Dmitry Streblechenko" wrote: You need to unsubscribe from the event if mailItem!= null. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Okay, that worked like a champ. I can't believe I missed that. One last bug. So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
Reply/Reply All
The RemoveHandler part must come before AddHandler loop, otherwise you will
remove the handler that you just added. Also, your code will only handle one selected item - instead of using a single mailitem varisble, use a list. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Have a look: public class ThisApplication Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Public mailItem As Outlook.MailItem = Nothing Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection mailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next If (mailItem IsNot Nothing) Then RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) 'blah blah blah End Sub End Class "Dmitry Streblechenko" wrote: Did you first check that mailItem is not null? What is your latest code? Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Sorry Dmitry, but I cannot figure out the best place to put RemoveHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll At first I added it to the SectionChange routine, but that just killed the event, so then I thought I had to add it to the ReplyAll event after it runs, but that did nothing, same error. Sorry for all your time. I appreciate this. "Dmitry Streblechenko" wrote: You need to unsubscribe from the event if mailItem!= null. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Okay, that worked like a champ. I can't believe I missed that. One last bug. So in the code I sent last night, the MailItem_ReplyAll will run twice AFTER every selection change. If you are looking at your Outlook Inbox. You choose a specific e-mail, you choose Reply All, and the MailItem_ReplyAll routine runs twice. It's as if I'm not doing a good garbage collection on something. I thought it was MailItem but it's not. Any ideas? "Dmitry Streblechenko" wrote: The line Dim mailItem As Outlook.MailItem declares a local variable which will be freed (and hence its events will be dropped) as soon as it goes out of scope and the GC releases it. Store all such items in a list rather than keep them as local variables (or, worse yet, as a *single*local variable). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... Dmitry, as always, thank you for guiding me.... Here's the code I am using. Appears a little bugy in that it only allows it to capture the Reply All once until the next Explorer.SelectionChange event. Is there anyway to avoid that that so a user can Reply All/Cancel unlimited number of times? Dim WithEvents explorer As Outlook.Explorer = Nothing Dim selectedItems As New System.Collections.ArrayList() Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup explorer = Me.Explorers.Application.ActiveExplorer AddHandler explorer.SelectionChange, AddressOf explorer_SelectionChange End Sub Private Sub explorer_SelectionChange() Handles explorer.SelectionChange selectedItems.Clear() For Each selectedItems As Object In explorer.Selection Dim mailItem As Outlook.MailItem = TryCast(selectedItems, Outlook.MailItem) If (mailItem IsNot Nothing) Then AddHandler mailItem.ReplyAll, AddressOf mailItem_ReplyAll End If Next End Sub Private Sub mailItem_ReplyAll(ByVal Response As Object, ByRef Cancel As Boolean) If MsgBox("Are you sure?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ddd") = MsgBoxResult.No Then Cancel = True End If End Sub "Dmitry Streblechenko" wrote: Trap the selection change events (Explorer.SelectionChange). For each item in the Explorer.Selection collection, trap the Reply/ReplyAll events. If the user can also reply from an inspector, you need to also trap these events on all open inspectors. Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "DG" wrote in message ... VSTO and VB.Net 2005, is there REALLY a way to capture the Reply or Reply All events? I see lots of discussions about Inspectors, but there's nothing that actually captures the event. I see lots of code regarding assumptions such as the size of the e-mail is 0 and the Reciptients are greater than 1 but that would give me no way to cancel a Reply or Reply All. The goal is to prompt the user upon a Reply/Reply All and allow the user to cancel the event. In VB6 this was very possible using Item Events, but that seems to be gone in VSTO. Any ideas? Thanks, DG |
All times are GMT +1. The time now is 08:24 PM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com