Reply All and No attachment Reminder

Status
Not open for further replies.

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Outlook VBA gurus,

I am a little bit familiar with VBA language, mostly using Excel , however i am a newbie in this outlook forum and also new in outlook vba.

i am looking for a piece of code i.e event handler that whenever by accident if i am about to send a message "Reply All" then it would give me a prompt msgbox that "Are you sure you want to reply all?" and if click yes, it would send and if i click No then it would cancel.

Similarly, i need another piece of code that gives me a msgbox reminder if i am sending an email without any attachment.

i have seen some free Add-in in some websites, but i am a domain user that i do not have windows administrative privileges, therefore any add-in VSTO or any peice of code will help me.

any help is appreciated.

best regards
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
i have found the following code in forums but it does not work. it does not trigger the msgbox.

Code:
Option Explicit 
 
Dim WithEvents insp As Outlook.Inspectors 
 
Dim WithEvents mailItem As Outlook.mailItem 
 
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
 
End Sub 
 
Private Sub Application_Startup() 
 
Set insp = Application.Inspectors 
 
End Sub 
 
Private Sub insp_NewInspector(ByVal Inspector As Inspector)
   If Inspector.CurrentItem.Size = 0 And Inspector.CurrentItem.Class = olMail Then
      Set mailItem = Inspector.CurrentItem
   End If 
 
End Sub 
 
Private Sub mailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
   Dim msg As String
   Dim result As Integer
   msg = "Do you really want to reply to all?"
   result = MsgBox(msg, vbYesNo, "Reply All Check")
   If result = vbNo Then
       Cancel = True
   End If 
 
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is all you need to check for attachments - it looks for the word attach in the message body.

Code:
Private WithEvents oItem As MailItem 
 
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
       If Item.Attachments.Count = 0 Then
         answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
         If answer = vbNo Then Cancel = True
       End If
  End If 
 
End Sub
for reply all, see http://www.outlookcode.com/codedetail.aspx?id=1299
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thank you very much Ms. Poremsky

very much appreciated.

the code on the Reply All worked perfectly. However the event handler code for attachment, did not give me any msgbox warning.

perhaps i might have placed the code into the wrong place. currently it is in the Microsoft Outlook Object ThisOutlookSession

thank you very much again.

This is all you need to check for attachments - it looks for the word attach in the message body.

Code:
Private WithEvents oItem As MailItem 
 
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
       If Item.Attachments.Count = 0 Then
         answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
         If answer = vbNo Then Cancel = True
       End If
  End If 
 
End Sub
for reply all, see http://www.outlookcode.com/codedetail.aspx?id=1299
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
following to my comments below, i found that i have a image in my signature block and that outlook thinks that it is an attachment. therefore, from one of your messages i found that i need to use the following code. however this code is stopped by debugger at line If Item.Attachments.Count > 1 with error of Object doesn't support this property or method.

any idea why i am getting this error?

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
       If Item.Attachments.Count = 0 Then
         answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
         If answer = vbNo Then Cancel = True
       End If
       If Item.Attachments.Count > 1 And Item.Attachments.Size > 5200 Then
         answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
         If answer = vbNo Then Cancel = True
       End If
  End If 
 
End Sub
Thank you very much Ms. Poremsky

very much appreciated.

the code on the Reply All worked perfectly. However the event handler code for attachment, did not give me any msgbox warning.

perhaps i might have placed the code into the wrong place. currently it is in the Microsoft Outlook Object ThisOutlookSession

thank you very much again.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You missed Private WithEvents oItem As MailItem? That goes at the very top of the module
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
i have also put that declaration at the very top, but still on the attachments.size property i get error.

You missed Private WithEvents oItem As MailItem? That goes at the very top of the module
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
i have a feeling that the size property item.attachments.size does not work . am i missing something?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I'm ok, really. :) You don't need the withevents for itemsend. :)

I'm trying to remember if i typo'd something. THe original code to check the size doesn't make sense - you need to check for smaller than 5200.

try this version -

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
If Item.Attachments.Count = 0 Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If

If Item.Attachments.Count > 0 Then
For Each oAtt In Item.Attachments
Debug.Print oAtt.Size
If oAtt.Size < 5200 Then
GoTo NextAtt
Else
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If

NextAtt:
Next oAtt

End If

End If
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i have a feeling that the size property item.attachments.size does not work . am i missing something?
it does, but not with AttachmentS, it works on individual attachments with in the attachments collection.
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thanks a million Ms. Poremsky


You are genius indeed.






I'm ok, really. :) You don't need the withevents for itemsend. :)




I'm trying to remember if i typo'd something. THe original code to check the size doesn't make sense - you need to check for smaller than 5200.




try this version -








Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
If Item.Attachments.Count = 0 Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True



End If






If Item.Attachments.Count > 0 Then
For Each oAtt In Item.Attachments
Debug.Print oAtt.Size
If oAtt.Size < 5200 Then
GoTo NextAtt
Else
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If




NextAtt:
Next oAtt



End If




End If



End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
LOL. Some days I'm a genius, other days I'm the dead squirrel in the middle of the road.

Thanks. :)
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
this code was very interesting. i changed it to 6000 . now it works good, except that when i attached even a file bigger than 6000 byte it will still intercept with msgbox.

i thought for an hour to modify the code, trigerring that for each oAtt in Item.Attachment if the any of the oAtt size is greater than 6000 bytes then do not show messagebox. somehow i am not that smart to workout the code.

any help is appreciated.

Code:
 Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
If Item.Attachments.count = 0 Then 
 
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True 
 
End If 
 
If Item.Attachments.count > 0 Then
For Each oAtt In Item.Attachments 
 
Debug.Print oAtt.Size
If oAtt.Size [COLOR=#FF0000]>[/COLOR] [COLOR=#FF0000]6000[/COLOR] Then 
 
GoTo NextAtt
Else 
 
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If 
 
NextAtt:
Next oAtt
End If 
 
End If 
 
End Sub
I'm ok, really. :) You don't need the withevents for itemsend. :)

I'm trying to remember if i typo'd something. THe original code to check the size doesn't make sense - you need to check for smaller than 5200.

try this version -

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
If Item.Attachments.Count = 0 Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If

If Item.Attachments.Count > 0 Then
For Each oAtt In Item.Attachments
Debug.Print oAtt.Size
If oAtt.Size < 5200 Then
GoTo NextAtt
Else
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If

NextAtt:
Next oAtt

End If

End If
End Sub
 

jamilm

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Please disregard my last message. i figured it out.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
Vijay Reply all by attachment name Using Outlook 10
C Outlook Attachment List in Reply Header Using Outlook 3
C Reply to all or reply to the To: Field with attachment Using Outlook 1
D Outlook 2010 Client crashes on new message, reply, forward, send as attachment Using Outlook 3
D Outlook 2010 crashes when I select new message, reply, forward or send as attachment Using Outlook 3
G Custom Forms: Attachment to be included in Reply Outlook VBA and Custom Forms 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
W Replyin to the reply-to email address Outlook VBA and Custom Forms 0
D Reply with a template loose the sender's embedded image Outlook VBA and Custom Forms 0
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
J Outlook Reply > From > Other Email Address... > Address Not Showing in Sent Items... From Email Outlook VBA and Custom Forms 0
M Delete headers in Inline reply Outlook VBA and Custom Forms 5
E reply Using Outlook 0
Healy Consultants Macro to remove inside organization distribution list email address when reply to all recepients Outlook VBA and Custom Forms 0
B resend if no reply and send an automatic reminder Outlook VBA and Custom Forms 0
evdbogaard Reply with only last message cited Using Outlook 1
B Reply and replyall macro is not working Outlook VBA and Custom Forms 1
mctabish Setting "Reply To" based on inbox Outlook VBA and Custom Forms 2
Rupert Dragwater Deleted email address keeps showing up in reply Using Outlook 12
B When working on emails in a certain folder, when I hit reply or reply all, I would like it re always reply all and add an email address to send to Outlook VBA and Custom Forms 3
R How Do I insert images in and Auto Reply Using Outlook 3
D Disable or hide "reply" and "reply to all" and "forward" in email from access vba Outlook VBA and Custom Forms 1
M Reply Inline With a Outlook Template Outlook VBA and Custom Forms 6
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
J VBA Run When Reply Outlook VBA and Custom Forms 4
D Font in Reply is much larger than normal, how to reset ...? Using Outlook 4
K add pdf to every reply or forward Outlook VBA and Custom Forms 1
A VB to "reply all" email items stored in a folder of outlook with adding a new message Outlook VBA and Custom Forms 0
K Extract email address from body and auto-reply outlook Using Outlook 1
T In-line reply style in Outlook Outlook VBA and Custom Forms 20
N Lookup Value From Excel and Reply With Matching Value Using Outlook 0
G Outlook 2016: reply icon not showing when replied from mobile Using Outlook 3
J Remove extra line above signature in reply Outlook VBA and Custom Forms 5
ashcosta2 Auto Reply rule based on speficied time Outlook VBA and Custom Forms 0
D Reply Problem with Outlook.com account Using Outlook.com accounts in Outlook 0
H send reminder if no reply received on first or original email using macro Using Outlook 2
Diane Poremsky Reply to All Includes My Address New Slipstick.com Articles 0
F Room Mailbox Reply Exchange Server Administration 0
N How to add Dear & mail receipts name while reply to that mail in outlook2007 Outlook VBA and Custom Forms 1
J Force account selection for sending reply emails Using Outlook 1
J Adding Reply & Delete to main toolbar? Using Outlook 0
Diane Poremsky Outlook Crashes When You Reply or Create a New Message New Slipstick.com Articles 0
S Outlook Macro Reply to a message Outlook VBA and Custom Forms 1
D Automatically file message and reply to folder. Using Outlook 1
O Reply and Add CC Outlook VBA and Custom Forms 4
S Default Calendar Reply Addresses Using Outlook 2
Fabio Quintal Reply All no longer working Using Outlook 9
Diane Poremsky Reply or ReplyAll with Attachments New Slipstick.com Articles 0
Diane Poremsky Remove an Address from Reply All New Slipstick.com Articles 0
Similar threads


















































Top