View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NateBuckley NateBuckley is offline
external usenet poster
 
Posts: 146
Default How to activate InputBox Cancel Function

I think when you click cancel it simple returns a 0 length string. So the
only way you can test if they clicked cancel is by checking the string that
is returned. Like so

Public Sub cancelInput()
Dim a As String
Dim hasPassword As Boolean
'Begin a loop that won't end till the user has inputted a password
While hasPassword = False
'assign the variable a to what ever Inputbox returns.
a = InputBox("Enter Password")
'If a's length is 0 then the user either clicked cancel
'or clicked OK with nothing entered.
If Len(a) = 0 Then
MsgBox ("Cancel or no password entered")
Else
MsgBox ("Your password is " & a)
hasPassword = True
End If
Wend
End Sub

Apart from checking the lenght or if a = "" don't think you can test it any
other way.

"Chua" wrote:

I use InputBox to display a simple dialog box so that User can enter
information to be used in a macro. The dialog box has an OK button and a
Cancel button. How do I activate the Cancel button to perform the function
that I want?

I tried below code but it will do nothing and exit the program even when
User click the OK button.

a = InputBox ("Enter Password to Proceed:")

If vbCancel = True Then
Do nothing
End If

If a < "12345" Then
MsgBox "INVALID PASSWORD !!!" & vbNewLine & "You have no administrator
rights to access the function.", vbCritical

End
End If