Consulting

Results 1 to 5 of 5

Thread: prevent sending certain file types - possible?

  1. #1

    prevent sending certain file types - possible?

    Hi All

    I would like to know if it is possible to prevent sending an .xlsm file type in Outlook 2016 via vba script?

    The environment I am in there is sensitive data in these file types and I would like to be able to prevent accidently sending of these file types.

    Very Much appreciated if anyone can point me in the right direction


  2. #2
    You could use the Outlook send event to check the attachments e.g. Save the following in the ThisOutlookSession module.
    See also http://www.gmayor.com/create_and_emp...gital_cert.htm which may be required.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim iAtt As Integer
    Dim strMsg As String
        If Item.Attachments.Count > 0 Then
            For iAtt = 1 To Item.Attachments.Count
                If Right(UCase(Item.Attachments(iAtt).fileName), 4) = "XLSM" Then
                    strMsg = "You are about to send an 'xlsm' format file. Are you sure?"
                    If MsgBox(strMsg, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check Attachments") = vbNo Then
                        Cancel = True
                    End If
                End If
            Next iAtt
        End If
    lbl_Exit:
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    thankyou so much! this works great

    if I wanted to add a second dialog box?

    for example: You are about to send an 'xlsm' format file. Are you sure?" if click yes then another dialog box with more text saying: are you REALLY sure?

    I know this may seem silly but im trying to make it as idiot proof as possible

    thanks again for your help - VERY much appreciated

  4. #4
    If you want it idiot proof, use the macro to remove the attachment.
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim iAtt As Integer
    Dim strMsg As String
        If Item.Attachments.Count > 0 Then
            For iAtt = 1 To Item.Attachments.Count
                If Right(UCase(Item.Attachments(iAtt).fileName), 4) = "XLSM" Then
                    strMsg = "You may not send 'xlsm' format files." & "The attachment has been removed."
                    MsgBox strMsg, vbCritical + vbMsgBoxSetForeground, "Blocked Attachments"
                    Item.Attachments.Remove iAtt
                    Cancel = True
                    Exit For
                End If
            Next iAtt
        End If
    lbl_Exit:
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    EXCELLENT!!

    thank you soo much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •