![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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 |
Ads |
#2
|
|||
|
|||
![]()
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 |
#3
|
|||
|
|||
![]()
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 |
#4
|
|||
|
|||
![]()
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 |
#5
|
|||
|
|||
![]()
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 |
#6
|
|||
|
|||
![]()
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 |
#7
|
|||
|
|||
![]()
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 |
#8
|
|||
|
|||
![]()
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 |
#9
|
|||
|
|||
![]()
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 |
#10
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating mailitem with reply/reply to all/forward buttons | chrisl | Outlook - Using Forms | 3 | June 22nd 07 12:55 AM |
Reply, Reply to All and Forward buttons are grey (can't use) | Vic | Outlook - Installation | 0 | May 25th 07 04:45 AM |
Get parent message (original) from the response created by Reply-All/Reply/Forward | Sanjay | Add-ins for Outlook | 3 | November 9th 06 06:02 PM |
Outlook 2003 does not reply with original reply headers indented | Sriram | Outlook - General Queries | 0 | May 17th 06 05:46 PM |
why cant I reply to certain recipients by reply or forwarding | kjmac308 | Outlook - General Queries | 2 | February 17th 06 07:45 PM |