I wrote the following code to prevent the email containing "@lifebloodsd.org" in the address of the person attempting to attach the excel workbook from a folder in a server. However, it does not work. How could this be rewritten differently so that it will work?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wb As Workbook
Set wb = ThisWorkbook
If Application.ActiveWindow.Caption Like "*lifebloodsd*" Then
MsgBox "You are not allowed to attach this file in email.", vbExclamation + vbOKOnly, "Error"
Cancel = True
End If
End Sub
Bookmarks