Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2016, 10:33 PM
gmayor's Avatar
gmayor gmayor is offline Outlook rule to not send if attachment name doesn't match criteria Windows 10 Outlook rule to not send if attachment name doesn't match criteria 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

The macro looks for an outgoing message with Personal Information in the attachment filename. It then strips the Personal Information text from the filename and looks to see if the remaining name is in the subject and then flags a warning no matter who the message is sent to.



The problem with using a distribution list is that it can only be identified as a list by looking at .To, if the list has not been expanded.

To see what I mean, send a message to the outbox (without sending immediately) with the three parameters correct then open and resend the message from the outbox. The message will still go through with the original code, but with the change below it will now not, because the sender is now the members of the group and not the group.

Based on your updated requirement, what I believe you now require would be to change

Code:
If InStr(1, Item.Subject, strCheck) = 0 Then
to
Code:
If InStr(1, Item.Subject, strCheck) = 0 Or Not Item.To = "Bob" Then
__________________
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
  #2  
Old 03-20-2016, 07:57 AM
SerenityNetworks SerenityNetworks is offline Outlook rule to not send if attachment name doesn't match criteria Windows 10 Outlook rule to not send if attachment name doesn't match criteria Office 2016
Advanced Beginner
Outlook rule to not send if attachment name doesn't match criteria
 
Join Date: May 2005
Location: Allen, Texas, USA
Posts: 37
SerenityNetworks
Default

Thank you. I'm on my phone right now, but will try to give it a shot later today.

In my case, I'm not concerned with users expanding the distribution list. The more simple and consistent the matching then the more simple the process (usage rules) the users have to follow.

Thanks again. I'll post back with the code I settle on.

Andrew
Reply With Quote
  #3  
Old 03-20-2016, 10:56 AM
SerenityNetworks SerenityNetworks is offline Outlook rule to not send if attachment name doesn't match criteria Windows 10 Outlook rule to not send if attachment name doesn't match criteria Office 2016
Advanced Beginner
Outlook rule to not send if attachment name doesn't match criteria
 
Join Date: May 2005
Location: Allen, Texas, USA
Posts: 37
SerenityNetworks
Default

This works perfectly for my needs. Thank you!

Code:
Option Explicit
    
'https://www.msofficeforums.com/outlook/30477-outlook-rule-not-send-if-attachment-name.html
'https://www.msofficeforums.com/member.php?u=26884

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 "*File*.*" Then
                strCheck = Replace(olAtt.FileName, _
                                   Right(olAtt.FileName, _
                                         Len(olAtt.FileName) - _
                                         InStrRev(olAtt.FileName, _
                                                  Chr(46)) + 1), "")
                strCheck = Replace(strCheck, "File ", "")
                'Use the following line of code to assure Group/Distribution Name, Subject, and Attachment all contain the same keyword.
                'If InStr(1, Item.Subject, strCheck) = 0 Or Not Item.To = strCheck Then
                'Use the following line of code to only check that Subject and Attachment contain the same keyword.
                If InStr(1, Item.Subject, strCheck) = 0 Then
                    MsgBox "Check the attachment(s)!"
                    Cancel = True
                    Exit For
                End If
            End If
        Next olAtt
    End If
lbl_Exit:
    Exit Sub
End Sub
Reply With Quote
Reply

Tags
block attachment, block sending, outlook rule



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a VLOOKUP - when 2 rows match criteria it returns the first value in the cel only how 2 change djrobst Excel 4 10-28-2015 01:32 AM
Outlook rule to not send if attachment name doesn't match criteria Count unique values that match 2 or more criteria caeiro01 Excel 1 10-25-2015 02:34 AM
Outlook macro to check a value of a cell in an attachment and send an email based on that value ketangarg86 Outlook 13 03-25-2015 07:11 AM
Outlook rule to not send if attachment name doesn't match criteria Outlook doesn't send/receive anymore. Astacus Outlook 1 12-29-2012 03:40 PM
Outlook rule to not send if attachment name doesn't match criteria Vlookup or Index/Match - Multiple Criteria ruci1225 Excel 1 01-15-2012 07:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft