[RESOLVED] Outlook 2003 - trying to have a check on a mail item
Hi,
My boss has expressed a wish for mail to tell him when he hasn't got an attachment on it but has the word attachment in the mail (ie please find an attachment of a spreadsheet....blah blah).
So I thought I'd have a go seeing as there is a VBA section to Outlook.
I started on the outlook application > thissession code module and started to make progress (ie a msgbox check) but for some reason the msgbox comes from the main outlook window, which is not highlighted from the mail item. Great. Vivsble property isn't there etc... usual. Not a huge problem, and something I can look at later.
Then Outlook died (pop up outlook had a problem and dr watson is trying to bring it back from the dead).
Re ran outlook, but now the events coding is not running. Its ignoring it completely.
Is there something I've missed?
Re: [RESOLVED] Outlook 2003 - trying to have a check on a mail item
For those of you who are interested - it reset the macro security to high thus ignored the code as it is unsigned.
Dropping the security to medium, and saying yes it will run it.
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim itm As MailItem
On Error Resume Next
Application.ActiveWindow.Display
'---- brings up a new instance that is created for the mail item (for some reason)
'Item.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Display
If (Item.Body Like "*attachment*" Or Item.Body Like "*attached*") And Item.Attachments.Count = 0 Then
Cancel = (MsgBox("Are you sure you want to send this email without any attachments?", vbYesNo + vbQuestion, "Uhhh") = vbNo)
End If
If Err.Number <> 0 Then
MsgBox "Error : " & Err.Number & vbCrLf & Err.Description, vbOKOnly + vbExclamation, "Error"
Err.Clear
End If
If Cancel Then Item.Display
End Sub
This was what I was trying to do :)