McGraw-Hill OnlineMcGraw-Hill Higher EducationLearning Center
Student Center | Instructor Center | Information Center | Home
Glossary
Data Files
Buzz in IT
Learning Objectives
Chapter Outline
Prerequisites
Multiple Choice Quiz
Short Answer
True or False
Case Problems
Hands-On Exercises
Feedback
Help Center


Advantage Series: Microsoft Word 2002
Advantage Series: Microsoft® Word 2002
Sarah Hutchinson-Clifford
Glen Coulthard

Exploring Visual Basic for Applications

Hands-On Exercises

Vernier Luxury Suites: Creating a Form

Joyce Wu is preparing the design for an online reservation system. She will be doing the preliminary design of the controls in Word. Assume the role of Joyce and perform the steps that she identifies.

  1. Open the "wd12xtra01.doc" Word file and save it as "Reservation Form" to your personal storage location.
  2. Display the Forms toolbar.
  3. Place the insertion point in the table cell to the right of the "Name" label and insert a text form field.
  4. Place text form fields in the table cells to the right of the labels "Arrival" and "Departure".
  5. Insert a drop down form field in the table cell to the right of the "Bed" label. Include the following options:
    • King
    • Queen
    • Double
  6. In the dialog box, click the Add Help Text command button. Then select the Status Bar tab.
  7. Select the Type your own option button and then type the following in the text box below:
    Choose a bed type from the list provided
  8. Close the displayed dialog boxes, saving your instructions, and return to the document.
  9. Insert check boxes immediately to the left of the labels "Smoking" and "Non-Smoking".
  10. Protect the form and save the revised "Reservation Form" document. The completed form appears in Figure 12.1.
  11.   Figure 12.1

    Completed form

    <a onClick="window.open('/olcweb/cgi/pluginpop.cgi?it=gif:: ::/sites/dl/free/0072471026/26780/WCh12_acq_Image1.gif','popWin', 'width=NaN,height=NaN,resizable,scrollbars');" href="#"><img valign="absmiddle" height="16" width="16" border="0" src="/olcweb/styles/shared/linkicons/image.gif"> (2.0K)</a>

  12. Test your work by tabbing through each form field and entering data. Then close the document without saving.

Data File: wd12xtra01 (25.0K)


TempSol Staffing: Enhancing Macros

TempSol agent Alyssa Karnes has created a few macros for importing job data in to a Word document. Her friend Dave is getting pretty good at VBA and decides to enhance the macros to be more user-friendly.

  1. Download the following files and save them to your personal storage location:
    • Wd12xtra02a.xls
    • Wd12xtra02b.xls
  2. Open the wd12xtra02.doc Word file and save it as "Job List Generator" in your personal storage location. ( Note: All three files must be in the same folder for the VBA code to execute correctly.)
  3. Notice the instructions and try out the macros.
  4. Open the Visual Basic Editor by pressing Alt key + F11 key
  5. Create a new procedure and call it AutoOpen. This will cause the procedure to run automatically when the document is open.
  6. CHOOSE: Insert, Procedure

    TYPE: AutoOpen as the name

    CLICK: OK button

  7. With the insertion point now in the newly created procedure, add a variable called "choice".
  8. TYPE: Dim choice As Integer

  9. Get input from the user by adding a message box.
  10. TYPE: choice = InputBox("Enter 1 for part-time and 2 for full-time.")

  11. Add an If…Then statement to launch the correct function.
  12. TYPE: If choice = 1 Then

    GetPartTime

    Else

    GetFullTime

    End If

    The full procedure is shown in figure 12.2.

      Figure 12.2

    New AutoOpen procedure

    <a onClick="window.open('/olcweb/cgi/pluginpop.cgi?it=gif:: ::/sites/dl/free/0072471026/26780/WCh12_acq_Image4.gif','popWin', 'width=NaN,height=NaN,resizable,scrollbars');" href="#"><img valign="absmiddle" height="16" width="16" border="0" src="/olcweb/styles/shared/linkicons/image.gif"> (2.0K)</a>

  13. Save the new code by clicking the save button and close the VBA Editor.
  14. Since the instructions are now moot, select and delete them.
  15. Save the document and close it.
  16. Re-open the document to test your new code. Close without saving.

Data File: wd12xtra02 (36.0K)
Data File: wd12xtra02a (13.0K)
Data File: wd12xtra02b (13.0K)


Jan Dice: Debugging a Macro

Jan Dice bills her clients by the hour. She has created an invoice template that uses macros and forms for easy input. However, something has gone wrong in her coding and now she is getting errors. So, she must face the task of debugging. Assume the role of Jan and perform the steps that she identifies.

  1. Open the "wd12xtra03.doc" Word file.
  2. Jan created a feature that automatically saves the document with a new name. When prompted, enter a new file name.
  3. You will get then get the error shown in figure 12.3. Click on the Debug button.
  4.   Figure 12.3

    Runtime Error

    <a onClick="window.open('/olcweb/cgi/pluginpop.cgi?it=gif:: ::/sites/dl/free/0072471026/26780/WCh12_acq_Image5.gif','popWin', 'width=NaN,height=NaN,resizable,scrollbars');" href="#"><img valign="absmiddle" height="16" width="16" border="0" src="/olcweb/styles/shared/linkicons/image.gif"> (6.0K)</a>

  5. In the VBA Editor window, the highlighted line of code contains a syntax error.
  6. Change the code:

    Selection.GoTo What:= wdGoToBookmark, Name:=" referenceNume r"

    To

    Selection.GoTo What:= wdGoToBookmark, Name:=" referenceNumber "

  7. Save the document over the original wd12xtra03.doc file and open it back up.
  8. Follow the prompts. Everything went fine, but the total is not correct. Close the document.
  9. Open the "wd12xtra03.doc" Word file, but disable the macros.
  10. Correct the equation that creates the total, "total = totalHour * rate"
  11. (Hint: One of the variable names is misspelled.)

  12. Save the document.
  13. Open the document and enable macros. The invoice now works as expected.

Data File: wd12xtra03 (43.0K)





McGraw-Hill/Irwin