I have attached one excel sheet. I have programmed this in such a way that it always asks the name of the person who opens this excel. Then the name & date with time autometically noted. I have used password "007" in this excel sheet.The code is below:-
Private Sub Workbook_Open()
'Prompt for name
Dim Ans As Variant
Ans = InputBox("Please enter your name.")
'Close the file if no name entered
If Ans = "" Then ThisWorkbook.Close False
Sheets("Main Sheet").Unprotect Password:="007"
'Enter name and date in the sheet
With Worksheets("Main Sheet")
.Range("B2") = Ans
.Range("C2") = Format(Now, "m/d/yyyy h:mm")
End With
Sheets("Main Sheet").Protect Password:="007"
End Sub
Afterwards, I have used the below programme for command button. It shows that if anyone click this button then the name & date with time will be noted in the "approved by" .
Private Sub CommandButton1_Click()
ActiveSheet.Unprotect Password:="007"
Range("E2") = Range("B2")
Range("F2") = Format(Now, "m/d/yyyy h:mm")
ActiveSheet.Protect Password:="007"
End Sub
Now I want a message box which should be appreared whenever we open this workbook & it should ask that whether "is it for new project?" we should select "yes" or "no". If "no" then E2 & F2 cells should be blank. If "yes" then it should follow as mentioned command button. This sheet is password protected "007".
I have given the screenshort of the sheet. Please help me.
Bookmarks