Eric89
01-28-2016, 12:21 PM
As mentioned in the title of the thread, I'm trying to get Outlook to check for attachments before sending an email. At this point, I've sent enough emails without the intended attachments that it's becoming increasingly annoying and embarrassing. My goal is that if the body contains "attach" in any way (e.g. attach, attached, attachment), it will check to see if there is indeed an attachment before sending. However, I do have a few images in my signature for my company logo, and a few icons for social media links. Thus, the code needs to detect whether there is an attachment exceeding a certain size, and if there is no attachment exceeding that size, it prompts me with a message saying that the email contains no attachment.
I found a VBA code online that seemed to match what I want, but it's not working at all. I tried editing the code to get it to work the way I want, but nothing I seem to do is working. The largest size of the image I have in my signature is about 18kb, but even if I try telling it to prompt me if there is no attachment larger than 18mb, the message still sends. This is the code I have so far:
-----
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim FoundAtt As Boolean
If InStr(1, Item.Body, "attached", 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
FoundAtt = False
For Each oAtt In Item.Attachments
Debug.Print oAtt.Size
If oAtt.Size < 18200000 Then
GoTo NextAtt
Else
FoundAtt = True
If FoundAtt = True Then Exit Sub
End If
NextAtt:
Next oAtt
If FoundAtt = False Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If
End If
End If
End Sub
-----
Could anybody please let me know what changes I need to make to get this to work? I'm running Outlook 2007. Thanks!
I found a VBA code online that seemed to match what I want, but it's not working at all. I tried editing the code to get it to work the way I want, but nothing I seem to do is working. The largest size of the image I have in my signature is about 18kb, but even if I try telling it to prompt me if there is no attachment larger than 18mb, the message still sends. This is the code I have so far:
-----
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim FoundAtt As Boolean
If InStr(1, Item.Body, "attached", 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
FoundAtt = False
For Each oAtt In Item.Attachments
Debug.Print oAtt.Size
If oAtt.Size < 18200000 Then
GoTo NextAtt
Else
FoundAtt = True
If FoundAtt = True Then Exit Sub
End If
NextAtt:
Next oAtt
If FoundAtt = False Then
answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
If answer = vbNo Then Cancel = True
End If
End If
End If
End Sub
-----
Could anybody please let me know what changes I need to make to get this to work? I'm running Outlook 2007. Thanks!