Nội dung text 14.5 VBA - Message Boxes and Input Boxes.pdf
IT & ITES COPA - Programming with VBA Message Boxes and Input Boxes Objectives: At the end of this exercise you shall be able to • display string data through MsgBox • use Input box to get numeric data • use Input box to get string data PROCEDURE Fig 3 TASK 1: Display string data through MsgBox 1 Open the Visual Basic Window in Excel. 2 Insert a module. 3 Type the following code in module1 code window. Sub test_messagebox() Dim strNameAs String strName = “Kumaravel K” MsgBox “Your Name is : “ &strName, vbOKOnly, “Your Name” End Sub 4 Run the code from the immediate window. TASK 2 : Use Input box to get numeric data 1 Open the Visual Basic Window in Excel. 2 Insert a module. 3 Write the following code in the code window. Sub test_inputbox() Dim age As Integer age = Application.InputBox(Prompt:="Please enter yourage.", Title:="AGE DETAILS", Type:=1) 'Type:=1 is for collecting a Numeric data type. Debug.Print "Your age is :" & age End Sub 4 Run the code from the immediate window. An Input Box is displayed as shown in Fig 2. 5 Enter the age and click "OK" 6 Check the result in the immediate window. (Refer Fig 3) Fig 1 Fig 2