A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Reply/Reply All



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 24th 07, 06:02 PM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default 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
Ads
  #2  
Old June 24th 07, 11:36 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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



  #3  
Old June 25th 07, 05:36 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default 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




  #4  
Old June 25th 07, 07:13 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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






  #5  
Old June 26th 07, 01:39 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default 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






  #6  
Old June 26th 07, 05:58 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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








  #7  
Old June 27th 07, 04:24 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default 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









  #8  
Old June 27th 07, 04:36 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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











  #9  
Old June 28th 07, 08:06 AM posted to microsoft.public.outlook.program_vba
DG
external usenet poster
 
Posts: 31
Default 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












  #10  
Old June 28th 07, 06:05 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default 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














 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating mailitem with reply/reply to all/forward buttons chrisl Outlook - Using Forms 3 June 21st 07 11:55 PM
Reply, Reply to All and Forward buttons are grey (can't use) Vic Outlook - Installation 0 May 25th 07 03:45 AM
Get parent message (original) from the response created by Reply-All/Reply/Forward Sanjay Add-ins for Outlook 3 November 9th 06 05:02 PM
Outlook 2003 does not reply with original reply headers indented Sriram Outlook - General Queries 0 May 17th 06 04:46 PM
why cant I reply to certain recipients by reply or forwarding kjmac308 Outlook - General Queries 2 February 17th 06 06:45 PM


All times are GMT +1. The time now is 08:33 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.