Alan McGowan
Senior Member
- Outlook version
- Outlook 2013 64 bit
- Email Account
- Exchange Server
Hi,
I am using the code below to check for missing attachments after you hit the send button. If no attachments are found and you choose yes from the msgbox then a userform loads and all it well. However, if you press no in the msg box what I want to happen is that you are returned back to the email message. At present if you press no the email is sent regardless. Any suggestions?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If UserForm1.TextBox4.Value = "YES" Then
Dim lngAns As Long
Dim varArray As Variant
Dim strWordFound As String
varArray = Array("Attached", "Attach", "Enclosed", "Enclose")
For lngCount = LBound(varArray) To UBound(varArray)
If InStr(1, Item.Body, varArray(lngCount), vbTextCompare) Or InStr(1, Item.Subject, varArray(lngCount), vbTextCompare) Then
strWordFound = strWordFound & "," & varArray(lngCount)
End If
Next
strWordFound = Mid(strWordFound, 2)
If Len(strWordFound) > 0 And Item.Attachments.Count = 0 Then
If MsgBox("You mention attachments but none were found. Do you want to send the mail anyway?", _
vbYesNo + vbQuestion, "Attachment Missing") = vbYes Then
If UserForm1.TextBox2.Value = "YES" Then
UserForm3.Show
Else
Exit Sub
End If
End If
End If
End If
End Sub
I am using the code below to check for missing attachments after you hit the send button. If no attachments are found and you choose yes from the msgbox then a userform loads and all it well. However, if you press no in the msg box what I want to happen is that you are returned back to the email message. At present if you press no the email is sent regardless. Any suggestions?
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If UserForm1.TextBox4.Value = "YES" Then
Dim lngAns As Long
Dim varArray As Variant
Dim strWordFound As String
varArray = Array("Attached", "Attach", "Enclosed", "Enclose")
For lngCount = LBound(varArray) To UBound(varArray)
If InStr(1, Item.Body, varArray(lngCount), vbTextCompare) Or InStr(1, Item.Subject, varArray(lngCount), vbTextCompare) Then
strWordFound = strWordFound & "," & varArray(lngCount)
End If
Next
strWordFound = Mid(strWordFound, 2)
If Len(strWordFound) > 0 And Item.Attachments.Count = 0 Then
If MsgBox("You mention attachments but none were found. Do you want to send the mail anyway?", _
vbYesNo + vbQuestion, "Attachment Missing") = vbYes Then
If UserForm1.TextBox2.Value = "YES" Then
UserForm3.Show
Else
Exit Sub
End If
End If
End If
End If
End Sub