Using Word VBA in Word2003 to make selection questions

Source: Internet
Author: User
Tags exit

VBA features in Word make Word documents interactive, and in school teaching, you can use Word VBA to make interactive selections in Word documents. To use Word2003 to make a two-item selection Word document as an example, the following steps are described:

Step 1th, create a blank Word document, enter the topic section of the selection question, such as "a complete computer system includes ()", and then set the font and font size according to the actual situation, as shown in Figure 2008070701.

Figure 2008070701 The question of the input selection question

The 2nd step opens the Control Toolbox by clicking the view → toolbar → Control toolbox menu command in the menu bar. Position the cursor in the appropriate position on the next line of the topic, and then click the check box button in the Control Toolbox, as shown in Figure 2008070702.

Figure 2008070702 Click the check box button

Step 3rd, right-click the Added check box control (CheckBox1) and select Properties on the Open shortcut menu, as shown in Figure 2008070703.

Figure 2008070703 Selecting the Properties command

Step 4th, open the Control Properties dialog box, modify name to DaAn1, and modify the character following the Caption property to the appropriate option (such as "A. Hardware System"), as shown in Figure 2008070704.

Figure 2008070704 The Properties dialog box

Step 5th, in the Properties dialog box, double-click the Font property option to set the font, size, and color for the answer in the Open Font dialog box, and other properties to leave the defaults set, as shown in Figure 2008070705.

Figure 2008070705 The Font dialog box

In step 6th, copy the check box that you just added to three. and modify their properties (such as "name" respectively modified to "DAAN2", "DaAn3", "DaAn4", "Caption" property modified to "B. System software", "C. Software system", "D. Office software"), As shown in Figure 2008070706.

Figure 2008070706 Modifying the check box control properties

Step 7th, position the cursor in the appropriate location on the next line of the answer, and then click the command button in the Control Toolbox, as shown in Figure 2008070707.

Figure 2008070707 Click the command button in the Control Toolbox

Step 8th, right-click the newly added command button, and select the Properties command. In the Open Control Properties dialog box, modify its name to PanDuan1, and the Caption property is modified to "Judge what is wrong", as shown in Figure 2008070708.

Figure 2008070708 Setting properties

Step 9th, double-click the command button that you just added, open the Visual Basic Editor window, and enter the code that determines the right error into the middle of the private Sub Panduan1_click () and End Sub code.

If Daan1.value = True and Daan2.value = False and Daan3.value = False and Daan4.value = True Then

MsgBox "Right, you're great!", vbOKOnly, "results"

Else

If Daan1.value = True and Daan2.value = True and Daan3.value = False and Daan4.value = False Or Daan1.value = True and DaA N2. Value = False and Daan3.value = True and Daan4.value = False Or Daan1.value = False and Daan2.value = True and Daan3.value = False and Daan4.value = True Or Daan1.value = False and Daan2.value = False and Daan3.value = True and Daan4.value = Tr UE Then

MsgBox "You only chose one, keep on cheering!", vbOKOnly, "hint."

Else

MsgBox "Sorry, you chose the wrong, think again!", vbOKOnly, "hint."

End If

End If

Close the Visual Basic Editor window when you finish typing, as shown in Figure 2008070709.

Figure 2008070709 Entering the VBA code

The above code means the following:

(1) If you select a and D and do not select B and C, press the "Right and wrong" pop-up message box "Yes, you're great!";

(2) If you select A and B and do not select C and D, press the "Right and wrong" pop-up message box "You've only chosen one, keep on cheering!";

(3) If you select A and C and do not select B and D, press the "Right and wrong" pop-up message box "You've only chosen one, keep on cheering!";

(4) If you choose B and D and do not select A and C, press the "Judge right or wrong" pop-up message box "You only got one, keep on cheering!";

(5) If you choose C and D and do not select a and B, press the "Right and wrong" pop-up message box "You've only chosen one, keep on cheering!";

(6) If you choose B and C and do not select a and D, or select more than three options, press the "Right and wrong" pop-up message box "I'm sorry, you chose a mistake, think again!"

Step 10th, add a button, modify its name to "ChongXuan1", and the "Caption" property to "select Again", as shown in Figure 2008070710.

Figure 2008070710 Modifying control properties

Step 11th, double-click the button to enter the following code in the VisualBasic editor window between private Sub Chongxuan1_click () and end Sub code.

Daan1.value = False

Daan2.value = False

Daan3.value = False

Daan4.value = False

Close the Visual Basic Editor window when you finish typing, as shown in Figure 2008070711.

Figure 2008070711 Entering the VBA code

Step 12th, click the Exit Design mode button in the Control Toolbox, and close the Control Toolbox, as shown in Figure 2008070712.

Figure 2008070712 Click the exit Design mode button

The run result of the choice question is shown in Figure 2008070713.

Figure 2008070713 Running Results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.