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
 
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
 
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
 
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
 
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.
 
You missed Private WithEvents oItem As MailItem? That goes at the very top of the module
 
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
 
i have a feeling that the size property item.attachments.size does not work . am i missing something?
 
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
 
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.
 
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
 
LOL. Some days I'm a genius, other days I'm the dead squirrel in the middle of the road.

Thanks. :)
 
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
 
Please disregard my last message. i figured it out.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Edit attachment Save and Reply Outlook VBA and Custom Forms 0
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
G Custom Forms: Attachment to be included in Reply Outlook VBA and Custom Forms 1
N Reply to Outlook messages by moving messages to a specific Outlook folder Outlook VBA and Custom Forms 1
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
nmanikrishnan Auto-reply from default account Using Outlook 1
P Automatic Greeting "Hello Name," when Reply All is clicked Outlook VBA and Custom Forms 1
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
S How to find emails that I sent that have not received a reply? Using Outlook 7
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
A Is there an ID field you can use to pair a reply to the sent email? Outlook VBA and Custom Forms 4
W Reply to email Using Outlook 4
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
C UDFs Reply vs Forward Outlook VBA and Custom Forms 3
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

Similar threads

Back
Top