I\'m very new to programming and I\'m just starting to learn VBA with excel. I came across on this website and did the examples here but I have question about this code:
<
6 and 7 are the return codes from the MsgBox method. Basically, when MsgBox is called, it shows a message-box to the user, who clicks either "Yes", "No", or "Cancel". The user's selection is returned from the MsgBox method as a number, where 6 is Yes, and 7 is No.
It is considered best-practice not to use these numbers in your code directly, but instead to use Microsoft supplied constants which represent them. Your code could be re-written as:
Private Sub CommandButton1_Click()
Dim message As Integer
message = MsgBox("Click Yes to Proceed, No to stop", vbYesNoCancel, "Login")
If message = vbYes Then
Range("A1").Value = "You may proceed"
ActiveWorkbook.Activate
ElseIf message = vbNo Then
ActiveWorkbook.Close
ElseIf message = vbCancel Then
'Do nothing.
End If
End Sub