Discussion:
Modifying value of To field on new mail
(too old to reply)
tyralia
2010-01-14 05:17:00 UTC
Permalink
Hello,

What I'm after, is for a way to remove certain address from the "To"
field whenever I hit reply-all to any message.

Any ideas would be appreciated.

Thanks!
Michael Bauer [MVP - Outlook]
2010-01-14 08:13:36 UTC
Permalink
A MailItem fires the ReplyAll event when you hit the button. In order to
receive that event, you need to set a variable declared WithEvents to the
item. That requires some work: Track the NewInspector event for opening
items, and track the SelectionChange event in order to set the variable to
the item whcih is currently selected in a folder.

Easier would be a prompt in the ItemSend event that asks you whether or not
to remove the address bevore sending.

In order to remove a certain address, remove it from the Recipients
collection.
--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>
Post by tyralia
Hello,
What I'm after, is for a way to remove certain address from the "To"
field whenever I hit reply-all to any message.
Any ideas would be appreciated.
Thanks!
tyralia
2010-01-14 09:46:23 UTC
Permalink
Hmm I was trying something along those lines I believe, from the MSDN
site on the ItemSend event where it shows some code to use, I grabbed
that and warped it into my existing code but now whenever I hit send I
get an error of "Object required" and the debugger highlights the
line: Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As
Boolean)

Here's the code:

Public WithEvents myOlItems As Outlook.Items
Public WithEvents myOlApp As Outlook.Application

Public Sub Application_Startup()
Set myOlItems = Session.GetDefaultFolder(olFolderInbox).Items
Set myOlApp = CreateObject("Outlook.Application")
MsgBox ("In startup")
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)
~~~~ blah blah ~~~~
End Sub

Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim prompt As String
Set myCount = 1
For Each objRecip In Item.Recipients
MsgBox (objRecip.Address)
If InStr(1, objRecip.Address, "***@gmail.com") Then
MsgBox ("bingo")
Item.Recipients.Remove myCount
End If
myCount = myCount + 1
Next

prompt = "Are you sure you want to send " & Item.Subject & "?"
If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo Then
Cancel = True
End If
End Sub
tyralia
2010-01-14 10:02:13 UTC
Permalink
Ok nevermind, it seems it was just because I was using 'Set' in the
line "Set myCount = 1", took that out and now it works.

Thanks for your help.

Loading...