View Single Post
 
Old 03-17-2016, 12:30 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

While you cannot do this with a rule, as rules on outgoing messages only apply after the message has been sent, you can do it with a macro. The following in the ThisOutlookSession module will check all outgoing messages for an attachment with 'Personal Information' in the filename. If it finds such an attachment, it will check if the Subject contains the name that follows Personal Information. If it does not the send will stop and you will see a warning message.

So for it to work, the attachment filename must be "Personal Information name.ext" (where ext is any file type) and the same name must be in the subject.

Code:
Option Explicit

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim olAtt As Attachment
Dim strCheck As String
Dim bCheck As Boolean
    If Item.Attachments.Count > 0 Then
        For Each olAtt In Item.Attachments
            If olAtt.FileName Like "*Personal Information*.*" Then
                strCheck = Replace(olAtt.FileName, _
                                   Right(olAtt.FileName, _
                                         Len(olAtt.FileName) - _
                                         InStrRev(olAtt.FileName, _
                                                  Chr(46)) + 1), "")
                strCheck = Replace(strCheck, " Personal Information", "")
                If InStr(1, Item.Subject, strCheck) = 0 Then
                    MsgBox "Check the attachment!"
                    Cancel = True
                    Exit For
                End If
            End If
        Next olAtt
    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 www.gmayor.com
Reply With Quote