PDA

View Full Version : Check email before send (Using Word as editor) - Outlook 2003



johncassell
06-03-2015, 02:05 AM
Hi, could someone help me figure this out please. I have the following code to check for missing attachments (I am going to make this include other things later on) but the problem is that the MsgBox pops up BEHIND the email (So the user has no idea that they are being prompted, they just think Outlook has hung). Any advice greatly appreciated. John


Private Sub NewApplication_ItemSend(ByVal Item As Object, Cancel As Boolean)

'## CHECK IF ITEM IS NEW E-MAIL BEFORE PROCEEDING:

If (Item.Class <> olMail) Then Exit Sub ' Ensure this is a mail message and not a task or other "item".
If (Item.Recipients.Count = 0) Then Exit Sub ' Exit early if there are no recipients.

'## CHECK FOR MISSING ATTACHMENT:

Dim mailContent As String
Dim pos As Integer
mailContent = Item.Body + Item.Subject ' Get a copy of all the e-mail body text and subject text to search.
mailContent = LCase(mailContent) ' Make whole string lowercase for easier searching.

If (Item.Attachments.Count = 0) Then ' If there are no attachments:
pos = InStr(1, mailContent, "attach")
If (pos > 0) Then ' If the word 'attach' appears:
res = MsgBox("You have used the word 'attach', but there is no attached file." & vbNewLine & _
"Do you wish to ignore this and send anyway?", vbYesNo)
If res = vbNo Then
Cancel = True
Exit Sub
End If
End If

End If
End Sub

skatonni
06-03-2015, 01:37 PM
Try vbMsgBoxSetForeground https://msdn.microsoft.com/en-us/library/aa445082(v=vs.60).aspx


res = MsgBox("You have used the word 'attach', but there is no attached file." & vbNewLine & _
"Do you wish to ignore this and send anyway?", vbYesNo + vbMsgBoxSetForeground)

johncassell
06-04-2015, 12:47 AM
Hi, thanks for the reply. I've sorted now but will retain your code for future work as I'm sure it will benefit me later on.

My code does the following (Outlook 2003 and Word 2003 as the email editor)

1. Checks for any missing attachments (if user has used attachment type words but there is no attachment)
2. It warns if you are sending to an external domain (It looks for the word MYEMAILDOMAIN anywhere in the email address you are sending to. If it can't find it then it reminds the user they are sending externally (We had problems with people sending sensitive stuff to Paul at Our Rival Company instead of Paul At Our Company
3. If its external then it delays the email from sending for 1-2minutes so they can grab it back if they realise they made an error.

For some reason it won't let me post the code but if anyone might find that useful then just reply to this or PM me.

Thanks again
John