Hi All,
I am trying to write a code that allow me to validate if a cell is (P44) is > 0 then an input box pops up to receive a numeric value of atleast 5 digits long.
once the user enters the required numeric value, the macro should allow the user to save the workbook in XLSM format only on his desktop.
if the required info is not filled on input box then the workbook should not be allowed to save at all.
The exsisting code allows to save in other formats if the user uses "Save As" option.
here is the code I am Using...
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim myValue As Variant
Application.EnableEvents = False
If SaveAsUI = True Then
If Range("P44") > 0 Then
myValue = InputBox("Please enter Your Meeting ID here", "Template Validation Program")
If Len(myValue) < 4 Or IsNumeric(myValue) = False Or myValue = "" Then
MsgBox "Meeting ID should be Numeric and greater than 5 Digits long", , "Template Validation Program "
Exit Sub
End If
Range("C13").Value = myValue
End If
MsgBox "Validation Successful, Template will be saved on to your Desktop...", , "Template Validation Program"
Cancel = True
ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("Username") & "\Desktop\" & ThisWorkbook.Name, FileFormat:=52
If FileNameVal = "False" Then 'User pressed cancel
Exit Sub
End If
Application.EnableEvents = False
End If
End Sub
Bookmarks