vba code to check the attachment format in Outlook

hearthhrob4gals

Board Regular
Joined
Aug 20, 2014
Messages
142
hi,

i need an outlook macro which should be triggered while clicking the send button. It should test the attachments and in case if there is any attachment apart from '.pdf' then it should display a dialogue box notifying the user and should cancel the send process...


Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Re: vba code to check the attachment format in look

Hello

Run the initialize handler routine first, to enable the event.

Code:
' ThisOutlookSession module


Public WithEvents myOlApp As Outlook.Application


Public Sub Initialize_handler()
Set myOlApp = Application
End Sub


Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim att As Attachments, i%, ext$
Set att = Item.Attachments
For i = 1 To att.Count
    ext = Split(att.Item(i).FileName, ".")(1)
    If ext <> "pdf" Then
        MsgBox "Above extension was found, aborting...", 16, UCase(ext)
        Cancel = True
        Exit Sub
    End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top