This is the
Workbook_BeforeSave code I am using:
Code:
Public Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, cancel As Boolean)
Dim ws As Worksheet
Set ws = ActiveSheet
Dim xFileName As String
Dim U7part As String, U8part As String, K13part As String
If (Range("U7") = Empty) Then
MsgBox "'Request number' is mandatory.", vbCritical, "text"
cancel = True
Range("U7").Select
End
Else
If (Range("U8") = Empty) Then
MsgBox "'Request date' is mandatory.", vbCritical, "text"
cancel = True
Range("U8").Select
End
Else
If (Range("K13") = Empty) Then
MsgBox "'Requesting Dept' is mandatory.", vbCritical, "text"
cancel = True
Range("K13").Select
End
Else
If (Range("L33") = "click here to select") Then
MsgBox "para. 3.b. 'Method of Delivery' is mandatory.", vbExclamation, "text"
cancel = True
Range("L33").Select
End
Else
If (Range("L37") = Empty) Then
MsgBox "para. 3.d. 'Date required by' is missing.", vbExclamation, "text"
cancel = True
Range("K37").Select
End
Else
Call RenameTemplateSheet
U7part = ws.Range("U7").value
U7part = Replace(Replace(U7part, " / ", "/"), "/", "_")
U8part = ws.Range("U8").value
U8part = Replace(Replace(U8part, " / ", "/"), "/", "_")
K13part = ws.Range("K13").value
K13part = Replace(K13part, "/", "_")
Range("U9").Select
If SaveAsUI <> False Then
cancel = True
xFileName = Application.GetSaveAsFilename(K13part & " text " & Range("A1").value & U7part & " dated " & U8part, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save As xlsm file")
If xFileName <> "False" Then
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:=xFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
Application.EnableEvents = True
End If
End If
End If
End If
End If
End If
End If
End Sub
Thanks heaps to any light you can shed on this....