The code below displays the dialog box we saw in the introduction.
InputBox "Please enter the documents title","Enter Title", "Document 1"
However, we need to know what the user entered! The InputBox function returns a string, which is the text the user entered in the Input Box.
DocName As String
DocName = InputBox ("Please enter the documents title", _
"Enter Title", "Document 1")
Msgbox "The documents title is " & DocName
This displays an input box asking the user for a documents title. When the user clicks OK then a Message Box will be displayed showing the text the user entered. You will notice that if you press cancel, the message box is still displayed. When the cancel button is pressed, the InputBox returns an empty string. You can edit the code so the message box is not displayed if the user presses cancel, or does not type anything:
DocName As String
DocName = InputBox ("Please enter the documents title", _
"Enter Title", "Document 1")
' If DocName is not empty, display the message box
If Not DocName = "" Then Msgbox "The documents title
is " & DocName
Comments