How to identify between ok and cancel button in inputbox

前端 未结 3 1634
情歌与酒
情歌与酒 2020-12-03 19:54

Hi Hi I have to write a code where if the user clicks enters something in the input box it should proceed further.If it doesnot enter any value it should throw back the same

3条回答
  •  感情败类
    2020-12-03 20:40

    For InputBox(), you can use the default value to determine if the user clicked Cancel or if they clicked OK or hit Enter to continue without entering a value:

    Sub Get_TIN()
       TIN = Trim(InputBox("Enter the provider TIN:", "Provider TIN", "ex. 123456789"))
    
       If TIN = "" Then    'When CANCEL is clicked because "TIN" will be empty.
          MsgBox "You pressed Cancel. Program will now end.", vbExclamation + vbOKOnly, "Macro End"
          Exit Sub
       End If
    
       If IsEmpty(TIN) = False Then     'When OK is clicked or Enter pressed because default text will be stored. Next, set TIN to "".
          TIN = ""
       End If
    End Sub
    

提交回复
热议问题