Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xFileName As String
Dim myDir As String
' Specify the folder path they CANNOT save to
myDir = "C:\Excel Files\"
' Cancel original save and prompt for save
Cancel = True
xFileName = Application.GetSaveAsFilename(, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As xlsm file")
' Check to see if file name is restricted folder
If UCase(Left(xFileName, Len(myDir))) = UCase(myDir) Then
MsgBox "You cannot save file to " & myDir & " directory.", vbOKOnly, "TRY AGAIN!"
Cancel = True
Exit Sub
End If
' Save file if save was not cancelled
If xFileName <> "False" Then
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=xFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.EnableEvents = True
Else
MsgBox "Action Cancelled"
Cancel = True
Exit Sub
End If
End Sub