Inputbox prompt before closing excel asking for ===>


Posted by newbie on August 12, 2001 9:50 AM

Hello again..this just a thought but with all the expert here.
i think this is not impossible..

let say i have a wb named "abc.xls" for user to key in data..
after finished the work..maybe they want to save the wb
or closed the wb and save it....
is it possible...before they try to save or close(also save it)
the wb.. an input box will prompt for them to supply the correct
password ..let say "123"..they will have 3 times to supply the
correct password..if they failed..the wb will be close automatically
and all their work will not be saved..

Thanks and thanks again..i think this method can prevent
people from using unauthorised wb..in other word..stealing
other people works and claimed it for theirself..many thanks



Posted by steve w on August 12, 2001 12:15 PM

try something like this
steve w
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

a = 1
For a = 1 To 3
Msg = "Enter Password"


UserEntry = InputBox(Msg)

If UserEntry = "password" Then
ActiveWorkbook.Saved = True
Exit Sub
Else
MsgBox "Your password was incorrect."
If a = 3 Then
Application.DisplayAlerts = False
ActiveWorkbook.Close
Exit Sub
End If
End If
Next a


End Sub