PDA

View Full Version : [SOLVED:] Check for attachment before sending a Email from Outlook!!Help!!



Kumarcoolz
07-10-2013, 07:53 PM
I triuse this code in outlook to check for unfilled subject before sending a mail. i wanted to try to improve it with attachments too but it is not working. the code that i use is below:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim strAttach As String
strSubject = Item.Subject
'strAttach = Item.Attachment.Count
'If strAttach = 0 Then
' Prompt$ = "are there no attachment to this mail"
' If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
' Cancel = True
' End If
'End If
If Len(Trim(strSubject)) = 0 Then
Prompt$ = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub

Can any one suggest me a solution:help

skatonni
07-17-2013, 02:09 PM
Try this.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim lngAttach As Long
Dim strPrompt As String
strSubject = Item.Subject
lngAttach = Item.Attachments.count
If lngAttach = 0 Then
strPrompt = "are there no attachment to this mail - Yes we have no attachments today"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Attachment") = vbNo Then
Cancel = True
End If
End If
If Len(Trim(strSubject)) = 0 Then
strPrompt = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub

Kumarcoolz
07-17-2013, 09:29 PM
Try this.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim lngAttach As Long
Dim strPrompt As String
strSubject = Item.Subject
lngAttach = Item.Attachments.count
If lngAttach = 0 Then
strPrompt = "are there no attachment to this mail - Yes we have no attachments today"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Attachment") = vbNo Then
Cancel = True
End If
End If
If Len(Trim(strSubject)) = 0 Then
strPrompt = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub


Thanks skatonni, but still the macro checks only for the subject and not the attachment:think:

skatonni
07-18-2013, 12:48 PM
Try this to see the attachment count.


Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strSubject As String
Dim lngAttach As Long
Dim strPrompt As String
strSubject = Item.Subject
lngAttach = Item.Attachments.count

If lngAttach = 0 Then

strPrompt = "are there no a
ttachment to this mail - Yes we have no attachments today"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Attachment") = vbNo Then
Cancel = True
End If

Else

Debug.Print "Attachments: " & lngAttach
' or
MsgBox "Attachments: " & lngAttach

End If

If Len(Trim(strSubject)) = 0 Then
strPrompt = "Subject is Empty. Are you sure you want to send the Mail?"
If MsgBox(strPrompt, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
End If
End If
End Sub


I would guess you have an attachment in your signature.
If so, either remove it or account for it with


If lngAttach = 1 Then

Kumarcoolz
07-30-2013, 11:54 PM
Worked a charm :-). you were right on the signature. it counted for 3.


Thanks skatonni :beerchug: