Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Office 2007 Excel Chapter 7 Using Macros and Visual Basic for Applications (VBA) with Excel.

Similar presentations


Presentation on theme: "Microsoft Office 2007 Excel Chapter 7 Using Macros and Visual Basic for Applications (VBA) with Excel."— Presentation transcript:

1 Microsoft Office 2007 Excel Chapter 7 Using Macros and Visual Basic for Applications (VBA) with Excel

2 Objectives Use passwords to assign protected and unprotected status to a worksheet Use the macro recorder to create a macro Execute a macro and view and print code for a macro Understand Visual Basic for Applications (VBA) code and explain event-driven programs Customize the Quick Access Toolbar by adding a button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition2

3 Objectives Add controls, such as command buttons, scroll bars, check boxes, and spin buttons to a worksheet Assign properties to controls Use VBA to write a procedure to automate data entry into a worksheet Understand Do-While and If-Then-Else statements Review a digital signature on a workbook Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition3

4 Plan Ahead Ascertain the steps needed to create a macro Create the user interface. In this chapter, two separate user interfaces are created that automate the entry of the employee’s investment model data Determine properties for controls in the user interface Establish the Visual Basic code needed for each control Evaluate the completed user interface through testing Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition4

5 Starting Excel and Opening a Workbook Start Excel Open the file Caliber from the Data Files for Students and then save the workbook using the file name, Caliber Steel If the Excel window is not maximized, double- click its title bar to maximize it 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition5

6 Starting Excel and Opening a Workbook Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition6

7 Entering Data in a Selected Range of Cells Select the range D5:D10. In cell D5, type Ali Kunar as the employee name and then press the ENTER key In cell D6, type 68400 as the annual salary and then press the ENTER key In cell D7, type 9% as the employee investment percentage and then press the ENTER key In cell D8, type 6% as the employer match percentage and then press the ENTER key In cell D9, type 8% as the annual return and then press the ENTER key 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 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition7

8 Entering Data in a Selected Range of Cells Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition8

9 Undoing a Group of Entries Using the Undo Button Click the Undo button arrow on the Quick Access Toolbar 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition9

10 Undoing a Group of Entries Using the Undo Button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition10

11 Un-protecting a Password-Protected Worksheet Click the Review tab on the Ribbon Click the Unprotect Sheet button to display the Unprotect Sheet dialog box When the Unprotect Sheet dialog box appears, type caliber in the Password text box Click the OK button to unprotect the 401(k) Investment Model worksheet Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition11

12 Un-protecting a Password-Protected Worksheet Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition12

13 Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook Click the Office Button to display the Office Button menu and then the Excel Options button to display the Excel Options dialog box Click the Show Developer tab in the Ribbon check box Click the OK button in the Excel Options dialog box to display the Developer tab on the Ribbon. Click the Developer tab Click the Macro Security button on the Ribbon to display the Trust Center dialog box When the Trust Center dialog box appears, click the ‘Enable all macros’ option button to select it Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition13

14 Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook Click the OK button to close the Macro Security dialog box Click the Office Button and then click Save As to display the Save As dialog box 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 Click the Save button in the Save As dialog box to save the workbook as an Excel Macro-Enabled Workbook file type Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition14

15 Displaying the Developer Tab, Enabling Macros, and Saving a Workbook as a Macro-Enabled Workbook Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition15

16 Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option If necessary, click the Developer tab on the Ribbon Click the Record Macro button on the Ribbon to display the Record Macro dialog box When the Record Macro dialog box appears, type PrintPortrait in the Macro name text box Type r in the Shortcut key text box to set the shortcut key for the macro to CTRL+R 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition16

17 Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option Click the OK button to begin recording the macro and cause the Record Macro button to become the Stop Recording button Click the Page Layout tab on the Ribbon Click the Page Setup Dialog Box Launcher to display the Page Setup dialog box 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 Click the Print button in the Page Setup dialog box Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition17

18 Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option When the Print dialog box displays, click the OK button to print the worksheet Click the Page Setup Dialog Box Launcher to display the Page Setup dialog box 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 Click the OK button to close the Page Setup dialog box Click the Developer tab on the Ribbon and then click the Stop Recording button to stop recording the worksheet activities Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition18

19 Recording a Macro to Print the Worksheet in Portrait Orientation Using the Fit to Option Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition19

20 Password-Protecting the Worksheet, Saving the Workbook and Closing the Workbook 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 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 Click the workbook’s Close button on the right side of its menu bar to close the workbook and leave Excel active Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition20

21 Setting the Macro Security Level to Medium Click the Developer tab on the Ribbon Click the Macro Security button on the Ribbon to display the Trust Center dialog box Click the ‘Disable all macros with notification’ option button Click the OK button in the Trust Center dialog box to close it Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition21

22 Setting the Macro Security Level to Medium Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition22

23 Opening a Workbook with a Macro and Executing the Macro With Excel active, open the Caliber Steel1 workbook Click the Options button in the Security Warning box to display the Microsoft Office Security Options dialog box Click the ‘Enable this content’ option button to select it Click the OK button When the Caliber Steel1 workbook opens, press CTRL+R to run the macro and print the worksheet Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition23

24 Opening a Workbook with a Macro and Executing the Macro Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition24

25 Viewing and Printing a Macro’s VBA Code Click the Developer tab on the Ribbon Click the Macros button on the Ribbon to display the Macro dialog box If necessary, when the Macro dialog box is displayed, click PrintPortrait in the Macro name list Click the Edit button to start the Microsoft Visual Basic Editor Use the scroll bar to scroll through the VBA code Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition25

26 Viewing and Printing a Macro’s VBA Code When you are finished, click File on the menu bar Click Print When the Print – VBA Project dialog box is displayed, click the OK button to print the macro code Click the Microsoft Visual Basic Editor Close button on the right side of the title bar Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition26

27 Viewing and Printing a Macro’s VBA Code Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition27

28 Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button Right-click anywhere on the Quick Access Toolbar to display the shortcut menu 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 Click the ‘Choose commands from’ box arrow Click Macros in the ‘Choose commands from’ list to display a list of macros If necessary, click the PrintPortait macro to select it Click the Add button to add the PrintPortrait macro to the Customize Quick Access Toolbar list Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition28

29 Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button Click the Modify button to display the Modify Button dialog box Click the printer icon (column 5, row 2) in the Symbol list Click the OK button to assign the printer icon to the new command and to close the Modify Button dialog box Click the OK button in the Excel Options dialog box to close it Point to the PrintPortrait button on the Quick Access Toolbar to display the ScreenTip for the button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition29

30 Adding a Button to the Quick Access Toolbar, Assigning the Button a Macro, and Using the Button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition30

31 Un-protecting a Password-Protected Worksheet With the Caliber Steel1 workbook open, 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 as the password and then click the OK button to unprotect the worksheet Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition31

32 Adding a Command Button Control to the Worksheet Click the Developer tab on the Ribbon Click the Insert button on the Ribbon to display the Controls gallery 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 Move the mouse pointer (a crosshair) to the upper-left corner of cell H5 Drag the mouse pointer so the rectangle defining the button area appears and hold Release the left mouse button to add the Command Button control with the default caption CommandButton1 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition32

33 Adding a Command Button Control to the Worksheet Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition33

34 Setting the Command Button Control Properties 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 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 Click ForeColor in the Properties list, click the ForeColor arrow, and then click the Palette tab Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition34

35 Setting the Command Button Control Properties Click blue (column 7, row 3) on the ForeColor palette Click Font in the Properties list and then click the Font button When the Font dialog box appears, click Bold in the Font style list and 12 in the Size list 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition35

36 Setting the Command Button Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition36

37 Entering the New Data Button Procedure Using the Visual Basic Editor With the New Data button selected and Excel in Design mode, point to the View Code button on the Ribbon Click the View Code button on the Ribbon to start the Microsoft Visual Basic Editor When the Microsoft Visual Basic Editor starts, if the Project Explorer window appears on the left, click its Close button If necessary, double-click the title bar to maximize the Microsoft Visual Basic Editor window If necessary, double-click the title bar of the Microsoft Visual Basic window to maximize it Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition37

38 Entering the New Data Button Procedure Using the Visual Basic Editor 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 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 Press the ENTER key to start a new line Position the insertion point on the blank line between the Sub and End Sub statements Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition38

39 Entering the New Data Button Procedure Using the Visual Basic Editor 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 Click the Close button on the right side of the Microsoft Visual Basic title bar to return to the worksheet Click the Close button on the right side of the Properties window Click the Design Mode button on the Ribbon to return to Run mode Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition39

40 Entering the New Data Button Procedure Using the Visual Basic Editor Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition40

41 Entering 401 (k) Investment Model Data Using the New Data Button Click the New Data button When Excel displays the first Enter dialog box with the prompt message, Employee Name?, type Millie Jenkins in the text box Click the OK button or press the ENTER key When Excel displays the next Enter dialog box with the prompt message, Annual Salary?, type 87200 in the text box Click the OK button 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition41

42 Entering 401 (k) Investment Model Data Using the New Data Button Click the OK button When Excel displays the next Enter dialog box with the prompt message, Employer Match in %?, type 3% in the text box Click the OK button When Excel displays the next Enter dialog box with the prompt message, Annual Return in %?, type 9% in the text box Click the OK button to assign 9.00% to cell D9 When Excel displays the next Enter dialog box with the prompt message, Years of Service?, type 20 in the text box Click the OK button to display the results for Millie Jenkins in the range F6:F10 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition42

43 Entering 401 (k) Investment Model Data Using the New Data Button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition43

44 Protecting a Worksheet and Saving the Workbook 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 appears, type caliber and then click the OK button 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 Click the Close button on the right side of the title bar to close the Caliber Steel2 workbook Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition44

45 Opening a Workbook and Un- protecting a Worksheet Open the Caliber Steel1 workbook saved in Phase 1 of this chapter 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 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 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition45

46 Adding Controls to a User Interface Select the range H5:L24 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 Click the Borders button arrow on the Ribbon and then click Thick Box Border on the Borders palette Click the Developer tab on the Ribbon 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition46

47 Adding Controls to a User Interface 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 Drag the mouse pointer so the Scroll Bar control displays Point to the Scroll Bar control 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 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 Drag the mouse pointer so the rectangle defining the Check Box control area displays with the word CheckBox1 showing Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition47

48 Adding Controls to a User Interface 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 Drag the mouse pointer so the rectangle defining the Spin Button control area displays Point to the Spin Button control in the Personalization Center 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 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition48

49 Adding Controls to a User Interface Drag the mouse pointer so the rectangle defining the Label control displays Point to the Label control 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. Continue in this fashion until you have a total of 11 Label controls Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition49

50 Adding Controls to a User Interface Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition50

51 Setting Properties of the Labe Controls and Checking Box Controls With Excel in Design mode, click the Label control in the top-right of the user interface 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 Release the SHIFT key Click the Properties button on the Ribbon When the Properties window opens, click Back- Color; if necessary, click the Back-Color box arrow; and then click the Palette tab Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition51

52 Setting Properties of the Labe Controls and Checking Box Controls 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 Click Font in the Properties window and then click the Font button When the Font dialog box appears, click Bold in the Font style list and click 12 in the Size list Click the OK button Click anywhere in the Personalization Center area to deselect the Label controls and Check Box control Click the Label control to the left of the first (Employee Investment) Scroll Bar control Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition52

53 Setting Properties of the Labe Controls and Checking Box Controls Click Caption in the Properties window and then type 0 as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 – fmTextAlignCenter Click the Label control to the right of the fi rst Scroll Bar control Click Caption in the Properties window and then type 13 as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition53

54 Setting Properties of the Labe Controls and Checking Box Controls If necessary, resize the Label control so the caption 13 is visible Click the Label control above the first Scroll Bar control Click Caption in the Properties window and then type Employee Investment as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Resize the Label control so the caption Employee Investment is visible Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition54

55 Setting Properties of the Labe Controls and Checking Box Controls Click the Label control to the left of the second Scroll Bar control Click Caption in the Properties window and then type 0 as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Click the Label control on the right side of the second Scroll Bar control Click Caption in the Properties window and then type 6 as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition55

56 Setting Properties of the Labe Controls and Checking Box Controls Click the Label control above the Personalization Center area Click Caption in the Properties window and then type Personalization Center as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Change the font style to 18-point, bold, and red Resize the Label control so the entire caption shows Select the range H2:L3 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 Click the Developer tab on the Ribbon Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition56

57 Setting Properties of the Labe Controls and Checking Box Controls Click the Label control directly above the second Scroll Bar Click Caption in the Properties window and then type Employer Match as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 2 - fmTextAlignCenter Resize the Label control so the entire caption shows Click the Label control to the far left of the top Spin Button control Click Caption in the Properties window and then type Annual Return (1% to 20%) as the caption Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition57

58 Setting Properties of the Labe Controls and Checking Box Controls Click TextAlign in the Properties window, click the TextAlign box arrow, and then, if necessary, click 1 - fmTextAlignLeft Resize the Label control so the entire caption shows Click the Label control to the far left of the second Spin Button control Click Caption in the Properties window and then type Years of Service (1 to 45 years) as the caption Click TextAlign in the Properties window, click the TextAlign box arrow, and then click 1 - fmTextAlignLeft Resize the Label control so the entire caption shows Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition58

59 Setting Properties of the Labe Controls and Checking Box Controls Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition59

60 Setting the Command Button Control Properties With Excel in Design mode, click the Command Button control in the Personalization Center Click Caption in the Properties window and then type Enter Name and Salary as the caption Click ForeColor, click the ForeColor box arrow, and then click the Palette tab Click red (row 4, column 2) on the ForeColor palette Click Font in the Properties window and then click the Font button 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 Resize the Command Button control so that the entire caption shows Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition60

61 Setting the Command Button Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition61

62 Setting the Employee Investment Scroll Bar Control Properties With Excel in Design mode, click the Employee Investment Scroll Bar control Click (Name) in the Properties window and then type scrEmployeeInvest as the name If necessary, change the LargeChange property to 100, the Max property to 1300, the Min property to 0, and the SmallChange property to 50 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition62

63 Setting the Employee Investment Scroll Bar Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition63

64 Setting the Employer Match Scroll bar Control Properties With Excel in Design mode, click the Employer Match Scroll Bar control Click (Name) in the Properties window and then type scrEmployerMatch as the name Change the LargeChange property to 100, the Max property to 600, the Min property to 0, and the SmallChange property to 25 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition64

65 Setting the Employer Match Scroll bar Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition65

66 Setting the Check Box Control Properties With Excel in Design mode, click the Check Box control Click (Name) in the Properties window and then type chkEmployerMatch as the name Click Alignment in the Properties window and then click 0 - fmAlignmentLeft Click Caption in the Properties window and then type Include Employer Match? as the caption Click SpecialEffect, click the box arrow in the Properties window, and then click 0 - fmButtonEffectFlat Click Value in the Properties window and then type True as the value Resize the Check Box control so the entire caption shows Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition66

67 Setting the Check Box Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition67

68 Setting Properties for the Annual Return and Years of Service Spin Button Controls With Excel in Design mode, click the Annual Return Spin Button control Click (Name) in the Properties window and then type spnAnnualReturn as the name If necessary, change the Max property to 2500, the Min property to 0, and the SmallChange property to 25 Click the Years of Service Spin Button control Click (Name) in the Properties window and then type spnYearsofService as the name Change the Max property to 45, the Min property to 1, and the SmallChange property to 1 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition68

69 Setting Properties for the Annual Return and Years of Service Spin Button Controls Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition69

70 Setting the Variable Label Control Properties With Excel in Design mode, click the Label control to the left of the Annual Return Spin Button control Click (Name) in the Properties window and then type lblAnnualReturn as the name Click Caption in the Properties window and then type 5% as the caption Change the BorderStyle property to 1 - fmBorderStyleSingle Change the BackColor property to white Change the TextAlign property to 3 - fmTextAlignRight Resize the Label control Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition70

71 Setting the Variable Label Control Properties Click the Label control to the left of the Years of Service Spin Button control Click (Name) in the Properties window and then type lblYearsofService as the name Click Caption in the Properties window and then type 10 as the caption Change the BorderStyle property to 1 - fmBorderStyleSingle Change the BackColor property to white Change the TextAlign property to 3 - fmTextAlignRight Resize the Label control Click the Close button on the right side of the Properties window title bar Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition71

72 Setting the Variable Label Control Properties Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition72

73 Resizing and Repositioning the Controls in the Personalization Center Cl ick the Properties button on the Ribbon If necessary, drag the Properties window to the left side of the Excel window Click the Enter Name and Salary Command Button control Change its Top, Left, Height, and Width properties to those listed in Table 7–4 to display the Enter Name and Salary Command Button 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 Close the Properties window and then deselect the Years of Service (1 to 45 years) label by clicking cell A1 Click the Save button on the Quick Access Toolbar to save the workbook using the file name, Caliber Steel3 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition73

74 Resizing and Repositioning the Controls in the Personalization Center Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition74

75 Entering the Enter Name and Salary Button Procedure With Excel in Design mode, click the View Code button on the Ribbon Click the Object box arrow at the top of the window and then click CommandButton1 in the alphabetical list 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 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition75

76 Entering the Enter Name and Salary Button Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition76

77 Entering the Employee Investment Scroll Bar Procedure With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click scrEmployeeInvest Enter the VBA code shown in Table 7–6 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition77

78 Entering the Employee Investment Scroll Bar Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition78

79 Entering the Employer Match Check Box Procedure With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click chkEmployerMatch Enter the VBA code shown in Table 7–7 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition79

80 Entering the Employer Match Check Box Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition80

81 Entering the Employer Match Scroll Bar Procedure With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click scrEmployerMatch. Enter the VBA code shown in Table 7–8 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition81

82 Entering the Employer Match Scroll Bar Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition82

83 Entering the Annual Return Spin Button Procedure With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click spnAnnualReturn Enter the VBA code shown in Table 7–9 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition83

84 Entering the Annual Return Spin Button Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition84

85 Entering the Years of Service Spin Button Procedure With the Visual Basic Editor active, click the Object box arrow at the top of the window and then click spnYearsofService Enter the VBA code shown in Table 7–10 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition85

86 Entering the Years of Service Spin Button Procedure Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition86

87 Closing the Visual basic Editor, Protecting the Worksheet, and Saving the Workbook Click the Close button on the right side of the Visual Basic Editor title bar When the Excel window is visible, click the Design Mode button on the Ribbon to exit Design mode Click the Review tab on the Ribbon and then click the Protect Sheet button on the Ribbon 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 Click the Save button on the Quick Access Toolbar to save the workbook using the file name, Caliber Steel3 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition87

88 Testing the Controls in the Personalization Center Click the Enter Name and Salary button in the Personalization Center When Excel displays the Enter dialog box with the prompt message, Employee Name?, type Gina Moira as the employee name When Excel displays the Enter dialog box with the prompt message, Annual Salary?, type the negative number –54500 as the annual salary When Excel displays the Enter dialog box with the prompt message, Annual salary must be > zero, type 54500 as the annual salary Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition88

89 Testing the Controls in the Personalization Center Use the Employee Investment scroll bar to change the value in cell D7 to 6% Click the Include Employer Match check box if it does not have a check mark Use the Employer Match scroll bar to change the value in cell D8 to 4% Click the Annual Return spin button arrows to change the value in cell D9 to 8.5% Click the Years of Service spin button arrows to change the value in cell D10 to 35 Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition89

90 Resetting the Quick Access Toolbar and Ribbon and Quitting Excel Right-click anywhere on the Quick Access Toolbar and then click Customize Quick Access Toolbar on the shortcut menu 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 Click the Office Button and then click the Excel Options button on the Office Button menu 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 Click the Close button on the right side of the title bar If the Microsoft Office Excel dialog box appears, click the No button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition90

91 Adding a Digital Signature to a Workbook 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 When the Signature Setup dialog box appears, type your name in the Suggested signer text box and then click the OK button When Excel adds the signature box to the workbook, right-click anywhere in the signature box and then click Sign on the shortcut menu 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 Click the OK button to digitally sign the document Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition91

92 Reviewing a Digital Signature on a Workbook Click the Office Button and then click Prepare on the Office Button menu Click View Signature on the Prepare submenu 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 When you are finished reviewing the certificate, click the OK button in the Signature Details dialog box Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition92

93 Summary Use passwords to assign protected and unprotected status to a worksheet Use the macro recorder to create a macro Execute a macro and view and print code for a macro Understand Visual Basic for Applications (VBA) code and explain event-driven programs Customize the Quick Access Toolbar by adding a button Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition93

94 Summary Add controls, such as command buttons, scroll bars, check boxes, and spin buttons to a worksheet Assign properties to controls Use VBA to write a procedure to automate data entry into a worksheet Understand Do-While and If-Then-Else statements Review a digital signature on a workbook Microsoft Office 2007: Comprehensive Concepts and Techniques - Windows Vista Edition94

95 Microsoft Office 2007 Excel Chapter 7 Complete


Download ppt "Microsoft Office 2007 Excel Chapter 7 Using Macros and Visual Basic for Applications (VBA) with Excel."

Similar presentations


Ads by Google