AttachmentAdd Event



Hi,

Can anyone explain to me how I would use the following code found in the
Outlook VBA help.

I have copied the code in to the project as explained and closed the VBA
editor, when I add an attachment I do not get a warning.

I am aiming to use this Event to warn if attachments are sent from certain
directories if this is possible. Can anyone put me on the right track?

Thanks in advance.
Richard




------------------------------------
Attachment Event
See AlsoApplies ToExampleSpecifics
Occurs when an attachment has been added to an item.

Sub object_AttachmentAdd(Attachment As Attachment)

object An object that evaluates to one of the objects in the Applies To
list. In Microsoft Visual Basic Scripting Edition (VBScript) in an Outlook
form, use the word Item.

Attachment Required. The Attachment that was added to the item.

Example
This Visual Basic for Applications (VBA) example checks the size of the item
after an attachment has been added and displays a warning if the size
exceeds 500,000 bytes. The sample code must be placed in a class module such
as ThisOutlookSession, and the TestAttachAdd() procedure should be called
before the event procedure can be called by Microsoft Outlook.

Public WithEvents newItem As Outlook.MailItem

Private Sub newItem_AttachmentAdd(ByVal newAttachment As Attachment)
If newAttachment.Type = olByValue Then
newItem.Save
If newItem.Size > 500000 Then
MsgBox "Warning: Item size is now " & newItem.Size & " bytes."
End If
End If
End Sub

Public Sub TestAttachAdd()
Dim olApp As New Outlook.Application
Dim atts As Outlook.Attachments
Dim newAttachment As Outlook.Attachment

Set newItem = olApp.CreateItem(olMailItem) newItem.Subject
= "Test attachment"
Set atts = newItem.Attachments
Set newAttachment = atts.Add("C:\Test.txt", olByValue)
End Sub
This VBScript example shows how to use the AttachmentAdd event in
VBScript.

Sub Item_AttachmentAdd(ByVal newAttachment)
If newAttachment.Type = 1 Then
Item.Save
If Item.Size > 500000 Then
MsgBox "Warning: Item size is now " & Item.Size & " bytes."
End If
End If
End Sub


.



Relevant Pages

  • Re: determine encryption?
    ... It is very small and is the only one: Remember Outlook 2002 VBA not Outlook Express.: ... Public Sub TestMail ... This email and Outlook 2002 VBA are not on good terms. ... If I don't this encryption breaks VBA and so my script rule. ...
    (microsoft.public.security)
  • Re: Outlook 2k3: VBA will not start
    ... It should run, but you should also be testing basic VBA functionality with a simpler procedure, e.g. ... Sub Hello ... Another thing you can try is to export your code if you want to keep it, shut down Outlook, rename the VbaProject.otm file, then restart Outlook. ... It is just a simple MsgBox in the Application_Startup ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Outlook 2k3: VBA will not start
    ... What do I use to kick off this sub? ... Sue Mosher, Outlook MVP ... of the VBA kicked in. ... the code window and is still there when I restart. ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: COM Addin Problem after Update to Outlook 2003
    ... It worked with Outlook 2000 and XP, ... Only the Addin wasn't loaded. ... > Private Sub IDTExtensibility2_OnAddInsUpdateAs Variant) ... > On Error GoTo ErrHandler ...
    (microsoft.public.outlook)
  • Re: COM Addin Problem after Update to Outlook 2003
    ... It worked with Outlook 2000 and XP, ... Only the Addin wasn't loaded. ... > Private Sub IDTExtensibility2_OnAddInsUpdateAs Variant) ... > On Error GoTo ErrHandler ...
    (microsoft.public.outlook.program_addins)