Excel chapter-7

2,089 views
2,013 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,089
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
316
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Excel chapter-7

  1. 1. Excel Chapter 7<br />Using Macros and Visual Basic for Applications (VBA) with Excel<br />
  2. 2. Objectives<br />Use passwords to assign protected and unprotected status to a worksheet<br />Use the macro recorder to create a macro<br />Execute a macro and view and print code for a macro<br />Understand Visual Basic for Applications (VBA) code and explain event-driven programs<br />Customize the Quick Access Toolbar by adding a button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  3. 3. Objectives<br />Add controls, such as command buttons, scroll bars, check boxes, and spin buttons to a worksheet<br />Assign properties to controls<br />Use VBA to write a procedure to automate data entry into a worksheet<br />Understand Do-While and If-Then-Else statements<br />Review a digital signature on a workbook<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  4. 4. Plan Ahead<br />Ascertain the steps needed to create a macro<br />Create the user interface. In this chapter, two separate user interfaces are created that automate the entry of the employee’s investment model data<br />Determine properties for controls in the user interface<br />Establish the Visual Basic code needed for each control<br />Evaluate the completed user interface through testing<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  5. 5. Starting Excel and Opening a Workbook<br />Start Excel<br />Open the file Caliber from the Data Files for Students and then save the workbook using the file name, Caliber Steel<br />If the Excel window is not maximized, double-click its title bar to maximize it<br />If the worksheet window in Excel is not maximized, click the Maximize button next to the Close button on its title bar to maximize the worksheet within Excel<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  6. 6. Starting Excel and Opening a Workbook<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  7. 7. Entering Data in a Selected Range of Cells<br />Select the range D5:D10. In cell D5, type Ali Kunar as the employee name and then press the ENTER key<br />In cell D6, type 68400 as the annual salary and then press the ENTER key<br />In cell D7, type 9% as the employee investment percentage and then press the ENTER key<br />In cell D8, type 6% as the employer match percentage and then press the ENTER key<br />In cell D9, type 8% as the annual return and then press the ENTER key<br />In cell D10, type 25 as the years of service and then press the ENTER key to display the new future value of $813,127.57 in cell F10<br />Click cell H5 to remove the selection from the range D5:D10. You may have to scroll down the worksheet to refresh the pointer in the range B16:B24<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  8. 8. Entering Data in a Selected Range of Cells<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  9. 9. Undoing a Group of Entries Using the Undo Button<br />Click the Undo button arrow on the Quick Access Toolbar <br />When the Undo list appears, drag from the top down through Ali Kunar and then release the left mouse button to change the range D5:D10 back to its original values. Click cell H5. You may have to scroll down the worksheet to refresh the pointer in the range B16:B24<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  10. 10. Undoing a Group of Entries Using the Undo Button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  11. 11. Un-protecting a Password-Protected Worksheet<br />Click the Review tab on the Ribbon<br />Click the Unprotect Sheet button to display the Unprotect Sheet dialog box<br />When the Unprotect Sheet dialog box appears, type caliber in the Password text box <br />Click the OK button to unprotect the 401(k) Investment Model worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  12. 12. Un-protecting a Password-Protected Worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  13. 13. Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook<br />Click the Office Button to display the Office Button menu and then the Excel Options button to display the Excel Options dialog box<br />Click the Show Developer tab in the Ribbon check box<br />Click the OK button in the Excel Options dialog box to display the Developer tab on the Ribbon.<br />Click the Developer tab<br />Click the Macro Security button on the Ribbon to display the Trust Center dialog box<br />When the Trust Center dialog box appears, click the ‘Enable all macros’ option button to select it<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  14. 14. Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook<br />Click the OK button to close the Macro Security dialog box<br />Click the Office Button and then click Save As to display the Save As dialog box<br />When the Save As dialog box appears, click the ‘Save as type’ box arrow and then click Excel Macro-Enabled Workbook in the ‘Save as type‘ list<br />Click the Save button in the Save As dialog box to save the workbook as an Excel Macro-Enabled Workbook file type<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  15. 15. Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  16. 16. Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option<br />If necessary, click the Developer tab on the Ribbon<br />Click the Record Macro button on the Ribbon to display the Record Macro dialog box<br />When the Record Macro dialog box appears, type PrintPortrait in the Macro name text box<br />Type r in the Shortcut key text box to set the shortcut key for the macro to CTRL+R<br />Make sure the ‘Store macro in‘ box displays This Workbook and then type Macro prints worksheet in portrait orientation on one page in the Description text box<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  17. 17. Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option<br />Click the OK button to begin recording the macro and cause the Record Macro button to become the Stop Recording button<br />Click the Page Layout tab on the Ribbon<br />Click the Page Setup Dialog Box Launcher to display the Page Setup dialog box<br />When the Page Setup dialog box displays, click the Page tab. If necessary, click Portrait in the Orientation area, and then click Fit to in the Scaling area<br />Click the Print button in the Page Setup dialog box<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  18. 18. Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option<br />When the Print dialog box displays, click the OK button to print the worksheet<br />Click the Page Setup Dialog Box Launcher to display the Page Setup dialog box<br />If necessary, when the Page Setup dialog box displays, click the Page tab; click Landscape in the Orientation area; click Adjust to in the Scaling area; and then, if necessary, type 100 in the % normal size box<br />Click the OK button to close the Page Setup dialog box<br />Click the Developer tab on the Ribbon and then click the Stop Recording button to stop recording the worksheet activities<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  19. 19. Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  20. 20. Password-Protecting the Worksheet, Saving the Workbook and Closing the Workbook<br />Click the Review tab on the Ribbon, and then click the Protect Sheet button on the Ribbon. When the Protect Sheet dialog box appears, type caliber in the ‘Password to unprotect sheet’ text box and then click the OK button. When the Confirm Password dialog box is displayed, type caliber and then click the OK button<br />Click the Office Button and then click Save As. When the Save As dialog box is displayed, type Caliber Steel1 in the File name text box. Make sure UDISK (E:) displays in the Save in box and then click the Save button in the Save As dialog box<br />Click the workbook’s Close button on the right side of its menu bar to close the workbook and leave Excel active<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  21. 21. Setting the Macro Security Level to Medium<br />Click the Developer tab on the Ribbon<br />Click the Macro Security button on the Ribbon to display the Trust Center dialog box<br />Click the ‘Disable all macros with notification’ option button<br />Click the OK button in the Trust Center dialog box to close it<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  22. 22. Setting the Macro Security Level to Medium<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  23. 23. Opening a Workbook with a Macro and Executing the Macro<br />With Excel active, open the Caliber Steel1 workbook<br />Click the Options button in the Security Warning box to display the Microsoft Office Security Options dialog box<br />Click the ‘Enable this content’ option button to select it<br />Click the OK button<br />When the CaliberSteel1 workbook opens, press CTRL+R to run the macro and print the worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  24. 24. Opening a Workbook with a Macro and Executing the Macro<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  25. 25. Viewing and Printing a Macro’s VBA Code<br />Click the Developer tab on the Ribbon<br />Click the Macros button on the Ribbon to display the Macro dialog box<br />If necessary, when the Macro dialog box is displayed, click PrintPortrait in the Macro name list<br />Click the Edit button to start the Microsoft Visual Basic Editor<br />Use the scroll bar to scroll through the VBA code<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  26. 26. Viewing and Printing a Macro’s VBA Code<br />When you are finished, click File on the menu bar<br />Click Print<br />When the Print – VBA Project dialog box is displayed, click the OK button to print the macro code<br />Click the Microsoft Visual Basic Editor Close button on the right side of the title bar<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  27. 27. Viewing and Printing a Macro’s VBA Code<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  28. 28. Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button<br />Right-click anywhere on the Quick Access Toolbar to display the shortcut menu<br />Click the Customize Quick Access Toolbar command on the shortcut menu to display the Customize the Quick Access Toolbar page of the Excel Options dialog box<br />Click the ‘Choose commands from’ box arrow<br />Click Macros in the ‘Choose commands from’ list to display a list of macros<br />If necessary, click the PrintPortait macro to select it<br />Click the Add button to add the PrintPortrait macro to the Customize Quick Access Toolbar list<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  29. 29. Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button<br />Click the Modify button to display the Modify Button dialog box<br />Click the printer icon (column 5, row 2) in the Symbol list<br />Click the OK button to assign the printer icon to the new command and to close the Modify Button dialog box<br />Click the OK button in the Excel Options dialog box to close it<br />Point to the PrintPortrait button on the Quick Access Toolbar to display the ScreenTip for the button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  30. 30. Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  31. 31. Un-protecting a Password-Protected Worksheet<br />With the Caliber Steel1 workbook open, click the Review tab on the Ribbon, and then click the Unprotect Sheet button on the Ribbon<br />When the Unprotect Sheet dialog box appears, type caliber as the password and then click the OK button to unprotect the worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  32. 32. Adding a Command Button Control to the Worksheet<br />Click the Developer tab on the Ribbon<br />Click the Insert button on the Ribbon to display the Controls gallery<br />Click the Command Button button in the ActiveX area of the Controls gallery (column 1, row 1 of ActiveX area) to switch to Design mode<br />Move the mouse pointer (a crosshair) to the upper-left corner of cell H5<br /> Drag the mouse pointer so the rectangle defining the button area appears and hold<br />Release the left mouse button to add the Command Button control with the default caption CommandButton1<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  33. 33. Adding a Command Button Control to the Worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  34. 34. Setting the Command Button Control Properties<br />With the Command Button control selected and Excel in Design mode, click the Properties button on the Ribbon to open the Properties window for the Command Button control<br />If necessary, when the Properties window opens, click the Alphabetic tab, click Caption in the Properties list, and then type New Data as the caption<br />Click ForeColorin the Properties list, click the ForeColor arrow, and then click the Palette tab<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  35. 35. Setting the Command Button Control Properties<br />Click blue (column 7, row 3) on the ForeColor palette<br />Click Font in the Properties list and then click the Font button<br />When the Font dialog box appears, click Bold in the Font style list and 12 in the Size list<br />Click the OK button to display the Command Button control. If necessary, drag the lower-right corner of the Properties window to make all of the properties display in the window<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  36. 36. Setting the Command Button Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  37. 37. Entering the New Data Button Procedure Using the Visual Basic Editor<br />With the New Data button selected and Excel in Design mode, point to the View Code button on the Ribbon<br />Click the View Code button on the Ribbon to start the Microsoft Visual Basic Editor<br />When the Microsoft Visual Basic Editor starts, if the Project Explorer window appears on the left, click its Close button<br />If necessary, double-click the title bar to maximize the Microsoft Visual Basic Editor window<br />If necessary, double-click the title bar of the Microsoft Visual Basic window to maximize it<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  38. 38. Entering the New Data Button Procedure Using the Visual Basic Editor<br />Click to the left of the letter P in the word Private on the first line and press the ENTER key to add a blank line before the Sub statement<br />Move the insertion point to the blank line and then type the seven comment statements (lines 1 through 7) in Table 7–2 on page EX 558. Make sure you enter an apostrophe (‘) at the beginning of each comment line<br />Press the ENTER key to start a new line<br />Position the insertion point on the blank line between the Sub and End Sub statements<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  39. 39. Entering the New Data Button Procedure Using the Visual Basic Editor<br />Enter lines 9 through 16 in Table 7–2. For clarity, indent all lines between the Sub statement and End Sub statement by three spaces<br />Click the Close button on the right side of the Microsoft Visual Basic title bar to return to the worksheet<br />Click the Close button on the right side of the Properties window<br />Click the Design Mode button on the Ribbon to return to Run mode<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  40. 40. Entering the New Data Button Procedure Using the Visual Basic Editor<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  41. 41. Entering 401 (k) Investment Model Data Using the New Data Button<br />Click the New Data button<br />When Excel displays the first Enter dialog box with the prompt message, Employee Name?, type Millie Jenkins in the text box<br />Click the OK button or press the ENTER key<br />When Excel displays the next Enter dialog box with the prompt message, Annual Salary?, type 87200 in the text box<br />Click the OK button<br />When Excel displays the next Enter dialog box with the prompt message, Employee Investment in %?, type 6% in the text box, making certain to type the percent (%) sign<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  42. 42. Entering 401 (k) Investment Model Data Using the New Data Button<br />Click the OK button<br />When Excel displays the next Enter dialog box with the prompt message, Employer Match in %?, type 3% in the text box<br />Click the OK button<br />When Excel displays the next Enter dialog box with the prompt message, Annual Return in %?, type 9% in the text box<br />Click the OK button to assign 9.00% to cell D9<br />When Excel displays the next Enter dialog box with the prompt message, Years of Service?, type 20 in the text box<br />Click the OK button to display the results for Millie Jenkins in the range F6:F10<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  43. 43. Entering 401 (k) Investment Model Data Using the New Data Button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  44. 44. Protecting a Worksheet and Saving the Workbook<br />Click the Review tab on the Ribbon, and then click the Protect Sheet button on the Ribbon<br />When the Protect Sheet dialog box appears, type caliber in the ‘Password to unprotect sheet’ text box and then click the OK button. When the Confirm Password dialog box appears, type caliber and then click the OK button<br />Click the Office Button and then click Save As on the Office Button menu. When the Save As dialog box is displayed, type Caliber Steel2 in the File name text box. Make sure UDISK 2.0 (E:) displays in the Address bar and then click the Save button<br />Click the Close button on the right side of the title bar to close the Caliber Steel2 workbook<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  45. 45. Opening a Workbook and Un-protecting a Worksheet<br />Open the Caliber Steel1 workbook saved in Phase 1 of this chapter<br />Click the Options button in the Security Warning box. When the Microsoft Office Security Options dialog box appears, click the ‘Enable this content’ option button and then click the OK button to close the dialog box<br />Click the Office Button and then click Save As on the Office Button menu. When the Save As dialog box is displayed, type Caliber Steel3 in the File name text box and then click the Save button in the Save As dialog box<br />Click the Review tab on the Ribbon and then click the Unprotect Sheet button on the Ribbon. When the Unprotect Sheet dialog box appears, type caliber in the Password text box, and then click the OK button to unprotect the worksheet<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  46. 46. Adding Controls to a User Interface<br />Select the range H5:L24<br />Click the Fill Color button arrow on the Home tab on the Ribbon and then click White, Background 1, Darker 25% (column 1, row 4) on the Fill Color palette<br />Click the Borders button arrow on the Ribbon and then click Thick Box Border on the Borders palette<br />Click the Developer tab on the Ribbon<br />Click the Insert button on the Ribbon, click the Command Button button in the ActiveX area in the Controls gallery, and then drag the mouse pointer so the control displays<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  47. 47. Adding Controls to a User Interface<br />Click the Insert button on the Ribbon, click the Scroll Bar button in the ActiveX area in the Controls gallery, and then move the mouse pointer to approximately the left of cell I12<br />Drag the mouse pointer so the Scroll Bar control displays<br />Point to the Scroll Bar control<br />Hold down the CTRL key and drag a copy of the Scroll Bar control to the location. It is important that you release the left mouse button before you release the CTRL key<br />Click the Insert button on the Ribbon, click the Check Box button in the ActiveX area in the Controls gallery, and then move the mouse pointer to the upper-left corner of the location of the Check Box control <br />Drag the mouse pointer so the rectangle defining the Check Box control area displays with the word CheckBox1 showing<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  48. 48. Adding Controls to a User Interface<br />Click the Insert button on the Ribbon, click the Spin Button button in the ActiveX area in the Controls gallery, and then move the mouse pointer to the upper-left corner of the location of the Spin Button control<br />Drag the mouse pointer so the rectangle defining the Spin Button control area displays<br />Point to the Spin Button control in the Personalization Center<br />Hold down the CTRL key and drag a copy of the Spin Button control to the second location. It is important that you release the left mouse button before you release the CTRL key<br />Click the Insert button on the Ribbon, click the Label button in the ActiveX area in the Controls gallery, and then move the mouse pointer to the left of the first Scroll Bar control below the CommandButton1 button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  49. 49. Adding Controls to a User Interface<br />Drag the mouse pointer so the rectangle defining the Label control displays<br />Point to the Label control<br />Hold down the CTRL key and then drag a copy of the Label control created in Step 7 to the center of cell J3. While holding down the CTRL key, drag the newly copied Label control to the next location where a Label control is required.<br />Continue in this fashion until you have a total of 11 Label controls<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  50. 50. Adding Controls to a User Interface<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  51. 51. Setting Properties of the Labe Controls and Checking Box Controls<br />With Excel in Design mode, click the Label control in the top-right of the user interface<br />Hold down the SHIFT key and then one at a time click the Check Box control and all Label controls except the title Label control<br />Release the SHIFT key<br />Click the Properties button on the Ribbon<br />When the Properties window opens, click Back-Color; if necessary, click the Back-Color box arrow; and then click the Palette tab<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  52. 52. Setting Properties of the Labe Controls and Checking Box Controls<br />Click the White, Background 1, Darker 25% (column 1, row 3) color on the BackColor palette to add a gray background to the selected controls<br />Click Font in the Properties window and then click the Font button<br />When the Fontdialog box appears, click Bold in the Font style list and click 12 in the Size list<br />Click the OK button<br />Click anywhere in the Personalization Center area to deselect the Label controls and Check Box control<br />Click the Label control to the left of the first (Employee Investment) Scroll Bar control<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  53. 53. Setting Properties of the Labe Controls and Checking Box Controls<br />Click Caption in the Properties window and then type 0 as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 – fmTextAlignCenter<br />Click the Label control to the right of the first Scroll Bar control<br />Click Caption in the Properties window and then type 13 as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  54. 54. Setting Properties of the Labe Controls and Checking Box Controls<br />If necessary, resize the Label control so the caption 13 is visible<br />Click the Label control above the first Scroll Bar control<br />Click Caption in the Properties window and then type Employee Investment as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />Resize the Label control so the caption Employee Investment is visible<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  55. 55. Setting Properties of the Labe Controls and Checking Box Controls<br />Click the Label control to the left of the second Scroll Bar control<br />Click Caption in the Properties window and then type 0 as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />Click the Label control on the right side of the second Scroll Bar control<br />Click Caption in the Properties window and then type 6 as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  56. 56. Setting Properties of the Labe Controls and Checking Box Controls<br />Click the Label control above the Personalization Center area<br />Click Caption in the Properties window and then type Personalization Center as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />Change the font style to 18-point, bold, and red<br />Resize the Label control so the entire caption shows<br />Select the range H2:L3<br />Click the Home tab on the Ribbon. Click the Borders button arrow on the Ribbon and then click Thick Box Border in the Borders gallery<br />Click the Developer tab on the Ribbon<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  57. 57. Setting Properties of the Labe Controls and Checking Box Controls<br />Click the Label control directly above the second Scroll Bar<br />Click Caption in the Properties window and then type Employer Match as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter<br />Resize the Label control so the entire caption shows<br />Click the Label control to the far left of the top Spin Button control<br />Click Caption inthe Properties window and then type Annual Return (1% to 20%) as the caption<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  58. 58. Setting Properties of the Labe Controls and Checking Box Controls<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then, if necessary, click 1 - fmTextAlignLeft<br />Resize the Label control so the entire caption shows<br />Click the Label control to the far left of the second Spin Button control<br />Click Caption in the Properties window and then type Years of Service (1 to 45 years) as the caption<br />Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 1 - fmTextAlignLeft<br />Resize the Label control so the entire caption shows<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  59. 59. Setting Properties of the Labe Controls and Checking Box Controls<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  60. 60. Setting the Command Button Control Properties<br />With Excel in Design mode, click the Command Button control in the Personalization Center<br />Click Caption in the Properties window and then type Enter Name and Salary as the caption<br />Click ForeColor, click the ForeColor box arrow, and then click the Palette tab<br />Click red (row 4, column 2) on the ForeColor palette<br />Click Font in the Properties window and then click the Font button<br />When the Font dialog box appears, click Bold in the Font style list, click 12 in the Size list, and then click the OK button<br />Resize the Command Button control so that the entire caption shows<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  61. 61. Setting the Command Button Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  62. 62. Setting the Employee Investment Scroll Bar Control Properties<br />With Excel in Design mode, click the Employee Investment Scroll Bar control<br />Click (Name) in the Properties window and then type scrEmployeeInvest as the name<br />If necessary, change the LargeChange property to 100, the Max property to 1300, the Min property to 0, and the SmallChange property to 50<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  63. 63. Setting the Employee Investment Scroll Bar Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  64. 64. Setting the Employer Match Scroll bar Control Properties<br />With Excel in Design mode, click the Employer Match Scroll Bar control<br />Click (Name) in the Properties window and then type scrEmployerMatch as the name<br />Change the LargeChange property to 100, the Max property to 600, the Min property to 0, and the SmallChange property to 25<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  65. 65. Setting the Employer Match Scroll bar Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  66. 66. Setting the Check Box Control Properties<br />With Excel in Design mode, click the Check Box control<br />Click (Name) in the Properties window and then type chkEmployerMatch as the name<br />Click Alignment in the Properties window and then click 0 - fmAlignmentLeft<br />Click Caption in the Properties window and then type Include Employer Match? as the caption <br />Click SpecialEffect, click the box arrow in the Properties window, and then click 0 - fmButtonEffectFlat<br />Click Value in the Properties window and then type True as the value<br />Resize the Check Box control so the entire caption shows<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  67. 67. Setting the Check Box Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  68. 68. Setting Properties for the Annual Return and Years of Service Spin Button Controls<br />With Excel in Design mode, click the Annual Return Spin Button control<br />Click (Name) in the Properties window and then type spnAnnualReturn as the name<br />If necessary, change the Max property to 2500, the Min property to 0, and the SmallChange property to 25<br />Click the Years of Service Spin Button control<br />Click (Name) in the Properties window and then type spnYearsofService as the name<br />Change the Max property to 45, the Min property to 1, and the SmallChange property to 1<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  69. 69. Setting Properties for the Annual Return and Years of Service Spin Button Controls<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  70. 70. Setting the Variable Label Control Properties<br />With Excel in Design mode, click the Label control to the left of the Annual Return Spin Button control<br />Click (Name) in the Properties window and then type lblAnnualReturn as the name<br />Click Caption in the Properties window and then type 5% as the caption<br />Change the BorderStyle property to 1 - fmBorderStyleSingle<br />Change the BackColor property to white<br />Change the TextAlign property to 3 - fmTextAlignRight<br />Resize the Label control<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  71. 71. Setting the Variable Label Control Properties<br />Click the Label control to the left of the Years of Service Spin Button control<br />Click (Name) in the Properties window and then type lblYearsofService as the name<br />Click Caption in the Properties window and then type 10 as the caption<br />Change the BorderStyle property to 1 - fmBorderStyleSingle<br />Change the BackColor property to white<br />Change the TextAlign property to 3 - fmTextAlignRight<br />Resize the Label control <br />Click the Close button on the right side of the Properties window title bar<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  72. 72. Setting the Variable Label Control Properties<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  73. 73. Resizing and Repositioning the Controls in the Personalization Center<br />Click the Properties button on the Ribbon<br />If necessary, drag the Properties window to the left side of the Excel window<br />Click the Enter Name and Salary Command Button control<br />Change its Top, Left, Height, and Width properties to those listed in Table 7–4 to display the Enter Name and Salary Command Button<br />One at a time, select the controls in the Personalization Center and change their Top, Left, Height, and Width properties to those listed in Table 7–4<br />Close the Properties window and then deselect the Years of Service (1 to 45 years) label by clicking cell A1<br />Click the Save button on the Quick Access Toolbar to save the workbook using the file name, Caliber Steel3<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  74. 74. Resizing and Repositioning the Controls in the Personalization Center<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  75. 75. Entering the Enter Name and Salary Button Procedure<br />With Excel in Design mode, click the View Code button on the Ribbon<br />Click the Object box arrow at the top of the window and then click CommandButton1 in the alphabetical list<br />Click before the P in Private and then press the ENTER key. Enter the lines 1 through 9 in Table 7–5 Click the blank line between the Sub and End Sub statements. Enter lines 11 through 22 in Table 7-5 being sure to indent each line of code by three spaces for readability<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  76. 76. Entering the Enter Name and Salary Button Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  77. 77. Entering the Employee Investment Scroll Bar Procedure<br />With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click scrEmployeeInvest<br />Enter the VBA code shown in Table 7–6<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  78. 78. Entering the Employee Investment Scroll Bar Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  79. 79. Entering the Employer Match Check Box Procedure<br />With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click chkEmployerMatch<br /> Enter the VBA code shown in Table 7–7<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  80. 80. Entering the Employer Match Check Box Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  81. 81. Entering the Employer Match Scroll Bar Procedure<br />With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click scrEmployerMatch.<br />Enter the VBA code shown in Table 7–8<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  82. 82. Entering the Employer Match Scroll Bar Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  83. 83. Entering the Annual Return Spin Button Procedure<br />With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click spnAnnualReturn<br />Enter the VBA code shown in Table 7–9<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  84. 84. Entering the Annual Return Spin Button Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  85. 85. Entering the Years of Service Spin Button Procedure<br />With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click spnYearsofService<br />Enter the VBA code shown in Table 7–10<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  86. 86. Entering the Years of Service Spin Button Procedure<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  87. 87. Closing the Visual basic Editor, Protecting the Worksheet, and Saving the Workbook<br />Click the Close button on the right side of the Visual Basic Editor title bar<br />When the Excel window is visible, click the Design Mode button on the Ribbon to exit Design mode<br />Click the Review tab on the Ribbon and then click the Protect Sheet button on the Ribbon<br />When Excel displays the Protect Sheet dialog box, type caliber in the ‘Password to unprotect sheet’ text box. Verify the password when prompted and then click the OK button<br />Click the Save button on the Quick Access Toolbar to save the workbook using the file name, Caliber Steel3<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  88. 88. Testing the Controls in the Personalization Center<br />Click the Enter Name and Salary button in the Personalization Center<br />When Excel displays the Enter dialog box with the prompt message, Employee Name?, type Gina Moira as the employee name<br />When Excel displays the Enter dialog box with the prompt message, Annual Salary?, type the negative number –54500 as the annual salary<br />When Excel displays the Enter dialog box with the prompt message, Annual salary must be > zero, type 54500 as the annual salary<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  89. 89. Testing the Controls in the Personalization Center<br />Use the Employee Investment scroll bar to change the value in cell D7 to 6%<br />Click the Include Employer Match check box if it does not have a check mark<br />Use the Employer Match scroll bar to change the value in cell D8 to 4%<br />Click the Annual Return spin button arrows to change the value in cell D9 to 8.5%<br />Click the Years of Service spin button arrows to change the value in cell D10 to 35<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  90. 90. Resetting the Quick Access Toolbar and Ribbon and Quitting Excel<br />Right-click anywhere on the Quick Access Toolbar and then click Customize Quick Access Toolbar on the shortcut menu<br />When the Excel Options dialog box appears, click the Reset button and then click the OK button in the Reset Customizations dialog box. Click the OK button to close the Excel Options dialog box<br />Click the Office Button and then click the Excel Options button on the Office Button menu<br />Click the ‘Show Developer tab in the Ribbon’ check box to remove the check mark and then click the OK button to close the Excel Options dialog box<br />Click the Close button on the right side of the title bar<br />If the Microsoft Office Excel dialog box appears, click the No button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  91. 91. Adding a Digital Signature to a Workbook<br />Click the Insert tab on the Ribbon and then click the Signature Line button on the Ribbon. If the Microsoft Office Excel dialog box appears, click the OK button<br />When the Signature Setup dialog box appears, type your name in the Suggested signer text box and then click the OK button<br />When Excel adds the signature box to the workbook, right-click anywhere in the signature box and then click Sign on the shortcut menu<br />When the Sign dialog box appears, type your name in the signature box or click the Select Image link to select a file that contains an image of your signature<br />Click the OK button to digitally sign the document<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  92. 92. Reviewing a Digital Signature on a Workbook<br />Click the Office Button and then click Prepare on the Office Button menu<br />Click View Signature on the Prepare submenu<br />Select a name from the Valid signature list in the signature pane and then click the button arrow next to the name. When the shortcut menu appears, click Signature Details<br />When you are finished reviewing the certificate, click the OK button in the Signature Details dialog box<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  93. 93. Summary<br />Use passwords to assign protected and unprotected status to a worksheet<br />Use the macro recorder to create a macro<br />Execute a macro and view and print code for a macro<br />Understand Visual Basic for Applications (VBA) code and explain event-driven programs<br />Customize the Quick Access Toolbar by adding a button<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  94. 94. Summary<br />Add controls, such as command buttons, scroll bars, check boxes, and spin buttons to a worksheet<br />Assign properties to controls<br />Use VBA to write a procedure to automate data entry into a worksheet<br />Understand Do-While and If-Then-Else statements<br />Review a digital signature on a workbook<br />© OpenCastLabs Consulting. www.opencast-labs.com <br />
  95. 95. Excel Chapter 7 Complete<br />

×