Sie sind auf Seite 1von 128

EXCEL 2003 MACROS

©Copyright 2004 SVI Training Products, Inc.


Information in this document is subject to change without notice, and does not
represent a commitment on the part of SVI Training Products, Inc. No part of this
manual may be reproduced or transmitted in any form, or by any means
whatsoever, without the written permission of SVI Training Products, Inc.

©Copyright 2004 SVI Training Products, Inc.

Microsoft, Windows and Visual Basic are registered trademarks of Microsoft


Corporation.

Any other company name, brand name, product name or logo mentioned or
illustrated in this publication may be a registered trademark or trademark of its
respective owner.

©Copyright 2004 SVI Training Products, Inc.


What does this logo mean?
It means this courseware has been approved by the Microsoftâ Office Specialist
Program to be among the finest available for learning Microsoft Office Excel 2003.
It also means that upon completion of this courseware (Microsoft Office Excel 2003
Macros) and the previous courseware in this series (Microsoft Office Excel 2003
Advanced), you may be prepared to take an exam for Microsoft Office Specialist
qualification.

What is a Microsoft Office Specialist?


A Microsoft Office Specialist is an individual who has passed exams for certifying
his or her skills in one or more of the Microsoft Office desktop applications such as
Microsoft Word, Microsoft Excel, Microsoft PowerPointâ, Microsoft Outlookâ, or
Microsoft Access. The Microsoft Office Specialist Program typically offers
certification exams at the “Specialist” and “Expert” skill levels. The Microsoft
Office Specialist Program is the only program in the world approved by Microsoft
for testing proficiency in Microsoft Office desktop applications. This testing
program can be a valuable asset in any job search or career advancement.

More Information:
To learn more about becoming a Microsoft Office Specialist, visit
www.microsoft.com/officespecialist.

To learn about other Microsoft Office Specialist approved courseware from SVI
Training Products, Inc., visit www.svitrain.com.

 The availability of Microsoft Office Specialist certification exams varies by application, application version and language.
Visit www.microsoft.com/officespecialist for exam availability.

Microsoft, the Microsoft Office Logo, PowerPoint, and Outlook are trademarks or registered trademarks of Microsoft
Corporation in the United States and/or other countries, and the Microsoft Office Specialist Logo is used under license from
owner.

©Copyright 2004 SVI Training Products, Inc.


APPENDIX A

VISUAL BASIC TIPS


AND TECHNIQUES

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Appendix A - Visual Basic Tips and Techniques

Appendix A VISUAL BASIC TIPS AND TECHNIQUES


Using the Copy and Paste Procedure

The standard Windows Copy and Paste procedure is available when you are working
in the Visual Basic Editor. For example, a block of code in one macro can be copied
onto the Windows Clipboard, pasted into another macro (even if it is in a different
workbook) and edited, as necessary.

Printing Macro Instructions

Using the File, Print command to print macro instructions can be an effective aid in
understanding the various Visual Basic statements.

Removing Unnecessary Lines

When you record a command that displays a dialog box, each option in that dialog
box is included in the macro, whether or not the option has been reset. The macro
instructions listed on the following page, for example, are the result of choosing the
File, Page Setup command and selecting options to 1) print the data in landscape
orientation, 2) center the data horizontally and vertically on the page, and 3) add the
custom left-aligned header "Company Confidential."

Many lines in this macro (those that are underlined) serve no useful purpose and may
even slow down macro execution. You can, however, either delete these unnecessary
lines or precede each with an apostrophe ('). (The latter technique marks the lines as
comments, which will be ignored when you run the macro.)

©Copyright 2004 SVI Training Products, Inc. Page A-1


Excel 2003 Macros Appendix A - Visual Basic Tips and Techniques

Sub PageSetup( )
With ActiveSheet.pageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.pageSetup.PrintArea = ""
With ActiveSheet.pageSetup
.LeftHeader = "Company Confidential"
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 300
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
End With
End Sub

©Copyright 2004 SVI Training Products, Inc. Page A-2


Excel 2003 Macros Appendix A - Visual Basic Tips and Techniques

Dealing With Errors

Excel provides several methods for debugging a macro and correcting errors.

1) Compile Errors

Visual Basic analyzes each instruction as you enter it. If it encounters an error in
syntax, it displays a compile error message, allowing you to correct the error before
running the macro.

Compile Error Message

Some compile errors are not identified until you attempt to run a macro. In this case,
the macro instructions are displayed in Debug mode, and you are given the
opportunity to correct the error at that point.

2) Run-time Errors

If, during the running of a macro, an instruction attempts an invalid operation, Visual
Basic displays a run-time error message.

Run-time Error Message

©Copyright 2004 SVI Training Products, Inc. Page A-3


Excel 2003 Macros Appendix A - Visual Basic Tips and Techniques

When a run-time error message appears, you have several options. You can:

 Click on the Debug button. Doing this displays the macro instructions in Debug mode,
allowing you to correct the error and continue.

 Click on the End button. Doing this cancels the execution of the macro instructions.

 Click on the Help button. Doing this displays Help information regarding the error.

3) Step Mode

Using the Debug, Step Into command or the Step Into button on the Debug
toolbar (in the Visual Basic Editor), you can step through a macro -- that is, execute
it one line at a time. This can help to identify an error.

©Copyright 2004 SVI Training Products, Inc. Page A-4


PRE-COURSE EVALUATION
The following evaluation will assist in determining your current knowledge of the
material presented in the following course. If you already know how to perform the
specified operation using Microsoft Office Excel 2003, check in the Yes column next
to that operation; otherwise check in the No column next to the operation.

OPERATION YES NO
Record a personal macro

Run a personal macro

Display macro instructions

Edit a macro

Include relative cell references in a macro

Record a workbook macro

Run a workbook macro

Add a macro button to a worksheet

Open a new module in the Visual Basic


Editor
Display a data prompt during macro
execution
Use a conditional statement in a macro

Use a control loop in a macro

Place a combo box on a worksheet

Place a check box on a worksheet

Link a control to worksheet data

Create a new toolbar

Add a button to a toolbar

Assign a macro to a toolbar button

(Continued)

©Copyright 2004 SVI Training Products, Inc.


OPERATION YES NO
Create a new menu

Add an item to a menu

Assign a macro to a menu item

Display Visual Basic Help information

©Copyright 2004 SVI Training Products, Inc.


SECTION 1

CONCLUSION

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 1 - Conclusion

1 CONCLUSION
You have just completed our Microsoft Office Excel 2003 Macros course. In the
course, you were introduced to many techniques. To reinforce your understanding of
these techniques, it is recommended that you read and work through this manual
once again. The manual will also serve as a valuable reference when you wish to
review any of the operations covered.

For information about any other SVI Training Products course, call 1-800-995-2798.

©Copyright 2002 SVI Training Products, Inc. Page 1


SECTION 2

FINAL CASE STUDY

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 2 - Final Case Study

2 FINAL CASE STUDY


The following Case Study will give you the opportunity to review and practice many
of the Excel features you have learned.

1. Open the workbook named Profit Forecast Model.xls.

2. The worksheet should include the name of the country to which the data refers. Place a
combination box (in or around cell D2) that displays the following options:

Australia
France
Germany
Great Britain
New Zealand
Japan
Taiwan
U.S.A.

3. Write a macro, named GetInfo, that prompts the user for the base sales amount, the growth rate
and the inflation rate. Have the macro display a warning if the base sales amount exceeds 10,000.
Also, ensure that only a growth rate between 0% and 10% and an inflation rate between 0% and
5% will be accepted.

4. Add a macro button to the worksheet to run the above macro.

5. Save the workbook.

6. Select an option in the combination box. Then run the GetInfo macro by using the macro
button.

7. A chart representing data in this worksheet has been plotted. The following two views have also
been created:

Chart -- to display the chart


Data -- to display the data

8. Record a workbook macro, named GoToChart, to display the Chart view.

9. Record another workbook macro, named GoToData, to display the Data view.

10. Save the workbook once again.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 2 - Final Case Study

11. Add a new command, named Special, to the Menu bar.

12. Assign the macros you have just recorded to items on the Special menu.

13. Run the GoToChart and GoToData macros by using the Special menu.

14. When you are finished, close the workbook, saving the changes.

Congratulations! You have completed the Case Study.

©Copyright 2004 SVI Training Products, Inc. Page 2


SECTION 3

USING THE VISUAL


BASIC HELP SYSTEM

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

3 USING THE VISUAL BASIC HELP SYSTEM


3.1 Introduction

This course has provided an introduction to the Visual Basic programming language.
You can enhance your knowledge of this language through the Visual Basic Help
system. In this section, you will learn how to:

 Display Visual Basic Help information.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

3.2 Displaying Visual Basic Help Information

You access the Visual Basic Help system from the Visual Basic Editor by choosing the
Help, Microsoft Visual Basic Help command or by clicking on the Microsoft
Visual Basic Help button on the Standard toolbar.

Microsoft Visual Basic Help Button

While working in the Visual Basic Editor, you can quickly obtain Help information for
the current item (for example, the statement, function or property in which the
insertion point is located) by pressing [F1].

In this exercise, you will access the Visual Basic Help system and display Help
information for Visual Basic operations.

1. Make sure that the Excel Application window is displayed.

You will begin by opening the Visual Basic Editor.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Microsoft Visual Basic window is
followed by Visual Basic Editor. displayed.
2. Click on the Microsoft Visual Basic The Visual Basic Help task pane is
Help button on the Standard toolbar. displayed.
3. In the Search box, type: Prompt A list of Search Results is displayed.
the user
Then click on the Start searching
button.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

ACTION (You Do) COMPUTER RESPONSE / Comments


4. Click on InputBox Method. Information about the InputBox Method is
displayed in the Help window (as
illustrated below).

5. Click on Example (near the top of An example of the InputBox function is


the Help window). displayed.
6. Click on the Back button on the The previous window of information is
toolbar of the Help window. redisplayed.

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

ACTION (You Do) COMPUTER RESPONSE / Comments


7. Click on the Show All button (near More detailed information about selected
the top of the Help window). items on the help screen is displayed (in
green).

8. Click on the Hide All button. The previous window of information is


once again displayed.

9. Click on the Close button on the Title The Help window is closed and the
bar of the Help window. Search Results task pane is displayed.
10. Click on Open Method. Information about the Open Method is
displayed in the Help window.
11. Click on the Close button on the Title The Help window is closed and the
bar of the Help window. Search Results task pane is displayed.
12. Click on the Close button on the The Help system is exited.
Search Results task pane.
13. Close the Visual Basic Editor.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

(Optional)

1. Access the Visual Basic Help system once again, and display information for topics of your
choice.

2. When you are finished, exit from the Help system, and close the Visual Basic Editor.

©Copyright 2004 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 3 - Using the Visual Basic Help System

3.3 Summary

In this section, you have learned how to:

 Display Visual Basic Help Use the Help, Microsoft Visual Basic
information. Help command or the Microsoft Visual
Basic Help button (from the Microsoft
Visual Basic window).

©Copyright 2004 SVI Training Products, Inc. Page 6


SECTION 4

CREATING A
MACROS MENU

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 4 - Creating a Macros Menu

4 CREATING A MACROS MENU


4.1 Introduction

This section discusses the methods for creating your own Macros menu. In it, you
will learn how to:

 Create a new menu.

 Add an item to a menu.

 Assign a macro to a menu item.

This section assumes that you have recorded several personal macros, including one
named MakeSales.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 4 - Creating a Macros Menu

4.2 Creating a New Menu

With Excel, you can also assign a macro to an item on a menu. This provides still
another method for running a macro. As your macros grow in number, you may wish
to create a special Macros menu from which all or a number of them can be
accessed.

Macros Menu

To create a new menu:

 Choose the Tools, Customize command.

 On the Commands panel of the Customize dialog box, which is subsequently displayed,
select the New Menu option in the Categories box.

 Drag the New Menu option from the Commands box to the Menu bar.

In this exercise, you will create a new menu. The options on this menu will be used
to run macros you have recorded.

1. Make sure that all workbooks are closed. Then open a new workbook (unless a new workbook is
already open).

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Customize The Customize dialog box is displayed.
command.
2. If the Commands panel does not
appear in the dialog box, click on the
Commands tab.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 4 - Creating a Macros Menu

ACTION (You Do) COMPUTER RESPONSE / Comments


3. In the Categories box, click on New The dialog box now appears as illustrated
Menu. below.

4. In the Commands box, point to the A new command is added to the Menu
New Menu option. Press and hold bar.
down the mouse button, and drag
this option to the right side of the
Menu bar (just after the Help
command). Then release the mouse
button.
5. Make sure that the new command A menu is displayed.
is selected. (It should be surrounded
by a dark border.) Then click on the
Modify Selection button in the
dialog box.

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 4 - Creating a Macros Menu

ACTION (You Do) COMPUTER RESPONSE / Comments


6. Select the current entry (New The command is renamed.
Menu) in the Name box.
Type: &Macros
Press [ENTER].

NOTE: The ampersand (&) indicates


the key that can be used in
combination with [ALT] (in this case,
"M") to activate the Macros
command.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 4 - Creating a Macros Menu

4.3 Adding an Item to a Menu / Assigning a Macro to a Menu Item

You are now ready to add an item to your new menu and assign a macro to that item.

To add an item to a menu:

 On the Commands panel of the Customize dialog box, select the Macros option in the
Categories box.

 Drag the Custom Menu Item option from the Commands box to the command name
(on the Menu bar) and then to the menu that appears.

 To modify the appearance of the item, click on the Modify Selection button (in the
Customize dialog box), and use the appropriate option(s) on the menu that appears.

To assign a macro to a menu item:

 Select the menu item, if necessary.

 On the Commands panel of the Customize dialog box, click on the Modify Selection
button.

 On the menu that appears, select the Assign Macro option.

 In the Assign Macro dialog box, which is then displayed, select the macro name.

 Click on the OK button.

In this exercise, you will add an item to your new Macros menu. You will then
modify this item and assign a macro to it.

1. Make sure that the Customize dialog box is open. (The Commands panel should currently appear
in the dialog box.)

©Copyright 2004 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 4 - Creating a Macros Menu

ACTION (You Do) COMPUTER RESPONSE / Comments


1. In the Categories box, click on The dialog box now appears as illustrated
Macros. below.

2. In the Commands box, point to the An item is added to the menu. You will
Custom Menu Item option. Press now modify it.
and hold down the mouse button,
and drag this option, first to the
Macros command on the Menu bar
and then to the empty menu that
appears below the command. Then
release the mouse button.
3. Make sure that the new menu item A menu is displayed.
is selected. Then click on the
Modify Selection button in the
dialog box.

©Copyright 2004 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 4 - Creating a Macros Menu

ACTION (You Do) COMPUTER RESPONSE / Comments


4. Select the current entry (&Custom The menu item is renamed. You will now
Menu Item) in the Name box. assign a macro to it.
Type: Make &Sales

NOTE: The ampersand (&) indicates


the key (in this case, "S") that can be
used to select the Make Sales option.
5. Make sure that the Modify The Assign Macro dialog box is displayed.
Selection menu is still displayed.
Then click on Assign Macro (on the
menu).
6. In the list of macros, double-click on The Assign Macro dialog box is closed,
PERSONAL.XLS!MakeSales. and the MakeSales macro is assigned to
the menu item.
7. Click on the Close button in the The dialog box is closed. You will now
Customize dialog box. use the new menu item to run the
associated macro.
8. Choose the Macros, Make Sales The macro is run.
command.
9. Close the workbook, without
saving it.

1. The menu item added in the previous exercise is used to run a personal macro. You can also
assign a workbook macro to a menu item. When a workbook macro is run via a menu item, Excel first
opens the associated workbook if it is not currently open.

2. This subsection has discussed the methods for adding an item to a custom menu. Using similar
methods, you can also add an item to any of Excel's default menus.

©Copyright 2004 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 4 - Creating a Macros Menu

This activity also demonstrates the method for removing a command from the Menu
bar.

1. Open a new workbook.

2. Add a second item to your Macros menu.

3. Assign a macro of your choice to this menu item.

4. Run the macro by using the new menu item (command sequence).

5. Close the workbook, without saving it.

6. Display the Customize dialog box. Then drag the Macros command from the Menu bar into
the dialog box. (Doing this removes the Macros command from the Menu bar.)

7. Close the Customize dialog box.

©Copyright 2004 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 4 - Creating a Macros Menu

4.4 Summary

In this section, you have learned how to:

 Create a new menu. Use the Tools, Customize command and


the New Menu option on the Commands
panel of the Customize
dialog box.

 Add an item to a menu. Use the Macros and Custom Menu


Item options on the Commands panel of
the Customize dialog box.

 Assign a macro to a menu item. Use the Modify Selection button on the
Commands panel of the Customize dialog
box and the Assign Macro option on the
subsequent menu.

©Copyright 2004 SVI Training Products, Inc. Page 9


SECTION 5

CREATING A
MACROS TOOLBAR

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

5 CREATING A MACROS TOOLBAR


5.1 Introduction

This section discusses the methods for creating your own Macros toolbar. In it,
you will learn how to:

 Create a new toolbar.

 Add a button to a toolbar.

 Assign a macro to a toolbar button.

This section assumes that you have recorded several personal macros, including one
named MakeSales.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

5.2 Creating a New Toolbar

Excel, as you know, provides several methods for running a macro. For example, you
can use:

 The Tools, Macro, Macros command.

 A shortcut key combination.

 A macro button on the worksheet.

The program also allows you to assign a macro to a button on a toolbar, thereby
providing another method for running a macro. As your macros grow in number, you
may wish to create a special Macros toolbar from which all or a number of them
can be accessed.

Macros Toolbar

To create a new toolbar:

 Choose the Tools, Customize command.

 On the Toolbars panel of the Customize dialog box, which is subsequently displayed, click
on the New button.

 In the New Toolbar dialog box, which is then displayed, enter a name for the toolbar.

 Click on the OK button.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

In this exercise, you will create a new toolbar. The buttons on this toolbar will be
used to run macros you have recorded.

1. Make sure that all workbooks are closed. Then open a new workbook (unless a new workbook is
already open).

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Customize The Customize dialog box is displayed.
command.
2. If the Toolbars panel does not appear The Toolbars panel of the Customize
in the dialog box, click on the dialog box is illustrated below.
Toolbars tab.

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

ACTION (You Do) COMPUTER RESPONSE / Comments


3. Click on the New button. The New Toolbar dialog box is displayed
(as illustrated below).

4. Type: Macros The toolbar name is entered.


5. Choose the OK button. The Customize dialog box is redisplayed.
A new, empty toolbar also appears next
to the dialog box.
6. On the new toolbar, point to the The toolbar is repositioned.
area below the Title bar. Press
and hold down the mouse button,
and drag the toolbar to the upper-
left corner of the Workbook
window. Then release the mouse
button.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

5.3 Adding a Button to a Toolbar / Assigning a Macro to a Toolbar Button

You are now ready to add a button to your new toolbar and assign a macro to that
button.

To add a button to a toolbar:

 On the Commands panel of the Customize dialog box, select the Macros option in the
Categories box.

 Drag the Custom Button option from the Commands box to the toolbar.

 To modify the appearance of the button, click on the Modify Selection button (in the
Customize dialog box), and use the appropriate option(s) on the menu that appears.

To assign a macro to a toolbar button:

 Select the button, if necessary.

 On the Commands panel of the Customize dialog box, click on the Modify Selection
button.

 On the menu that appears, select the Assign Macro option.

 In the Assign Macro dialog box, which is then displayed, select the macro name.

 Click on the OK button.

In this exercise, you will add a button to your new Macros toolbar. You will then
modify the appearance of this button and assign a macro to it.

1. Make sure that the Macros toolbar is displayed and that the Customize dialog box is open. (The
Toolbars panel should currently appear in the dialog box.)

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Click on the Commands tab in the The Commands panel of the dialog box is
Customize dialog box. displayed.
2. In the Categories box, click on The dialog now appears as illustrated
Macros. below.
©Copyright 2004 SVI Training Products, Inc. Page 5
Excel 2003 Macros Section 5 - Creating a Macros Toolbar

ACTION (You Do) COMPUTER RESPONSE / Comments

3. In the Commands box, point to the A button is added to the toolbar. You will
Custom Button option. Press and now modify its appearance.
hold down the mouse button, and
drag this option to the new
toolbar. Then release the mouse
button.
4. Make sure that the new button is A menu is displayed (as illustrated on the
selected. (It should be surrounded following page).
by a dark border.) Then click on the
Modify Selection button in the
dialog box.

©Copyright 2004 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

ACTION (You Do) COMPUTER RESPONSE / Comments

5. Select the current entry (&Custom The button is renamed.


Button) in the Name box.
Type: Make Sales
6. Click on Change Button Image on A list of images is displayed (as
the menu. illustrated below).

7. Click on an image of your choice. The button displays the image you have
chosen.
8. Click again on the Modify Selection Both the image and name now appear on
button. Then click on Image and the button. You will now assign a macro
Text on the menu that appears. to the button.

©Copyright 2004 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

ACTION (You Do) COMPUTER RESPONSE / Comments


9. Click once again on the Modify The Assign Macro dialog box is displayed.
Selection button. Then click on
Assign Macro on the menu that
appears.
10. In the list of macros, double-click on The Assign Macro dialog box is closed,
PERSONAL.XLS!MakeSales. and the MakeSales macro is assigned to
the button.
11. Click on the Close button in the The dialog box is closed. You will now
Customize dialog box. use the new button to run the associated
macro.
12. Click on the Make Sales button. The macro is run.
13. Close the workbook, without
saving it.
14. Click on the Close button on the Title The toolbar is removed from the Excel
bar of the Macros toolbar. Application window. You will now
redisplay it.
15. Choose the View, Toolbars The Macros toolbar is redisplayed.
command, followed by Macros.

The button added to the Macros toolbar in the previous exercise is used to run a
personal macro. You can also assign a workbook macro to a toolbar button. When a
workbook macro is run via a toolbar button, Excel first opens the associated
workbook if it is not currently open.

©Copyright 2004 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

This activity also demonstrates the methods for removing a button from a toolbar
and for deleting a toolbar.

1. Open a new workbook.

2. Add another button to your Macros toolbar.

3. Assign a macro of your choice to the button.

4. Run the macro by using the new button.

5. Close the workbook, without saving it.

6. Display the Customize dialog box. On the Macros toolbar, point to the Make Sales button.
Press and hold down the mouse button, and drag the Make Sales button into the dialog box. Then
release the mouse button. (Doing this removes the Make Sales button from the Macros toolbar.)

7. Display the Toolbars panel of the Customize dialog box. In the list of toolbars, click on the
toolbar name Macros, click on the Delete button, and then click on the OK button in the prompt box
that appears. (Doing this deletes the Macros toolbar.)

8. Close the Customize dialog box.

(Optional)

This subsection has discussed the methods for adding a macro button to a custom
toolbar. Using similar methods, you can also add a macro button to any of Excel's
default toolbars, as demonstrated in the next activity.

©Copyright 2004 SVI Training Products, Inc. Page 9


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

1. Open a new workbook.

2. Add a macro button to the Standard toolbar. (To do this, drag the Custom Button option from
the Commands panel of the Customize dialog box to the Standard toolbar. Place the new button to
the immediate left of the Microsoft Excel Help button.)

3. Assign a macro of your choice to this button (by using the Modify Selection button in the
Customize dialog box).

4. Run the macro by using the new button.

5. Close the workbook, without saving it.

6. Delete the new button from the Standard toolbar (by displaying the Customize dialog box and
by dragging the new button from the Standard toolbar into the dialog box).

©Copyright 2004 SVI Training Products, Inc. Page 10


Excel 2003 Macros Section 5 - Creating a Macros Toolbar

5.4 Summary

In this section, you have learned how to:

 Create a new toolbar. Use the Tools, Customize command and


the New button on the Toolbars
panel of the Customize dialog box.

 Add a button to a toolbar. Use the Macros and Custom Button


options on the Commands panel of the
Customize dialog box.

 Assign a macro to a toolbar Use the Modify Selection button on the


button. Commands panel of the Customize dialog
box and the Assign Macro option on the
subsequent menu.

©Copyright 2004 SVI Training Products, Inc. Page 11


SECTION 6

PLACING CONTROLS
ON A WORKSHEET

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

6 PLACING CONTROLS ON A WORKSHEET


6.1 Introduction

With Excel, you can place graphic objects, such as combo boxes, check boxes and
radio buttons, directly on a worksheet. These objects, called controls, can then be
linked to specific areas of the worksheet, thereby simplifying data entry.

In this section, you will learn how to:

 Place a combo box on a worksheet.

 Place a check box on a worksheet.

 Link a control to worksheet data.

This section assumes that you know how to record a macro and assign it to a macro
button on a worksheet. It also assumes that you know how to assign a name to a
range.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

6.2 Placing a Combo Box and Check Box on a Worksheet / Linking a


Control to Worksheet Data

Using a combo box (a combination of an edit box and list box) and/or a check box
in a worksheet is often beneficial when a particular entry must be one of a finite
number of options. In the worksheet illustrated below, for example, both a combo
box and a check box have been included for specifying the delivery method and
priority, respectively, of a shipment of goods. (The priority, in this case, is simply
true or false, depending on whether the box is selected or not.)

Worksheet with a Combo Box and Check Box

To place a combo box or check box on a worksheet:

 On the Forms toolbar, select the Combo Box button or the Check Box button.

 Draw the associated object by dragging the mouse pointer.

Combo Box Button Check Box Button

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

To link a control to worksheet data:


 Select the control, if necessary.
 Choose the Format, Control command, or select the Format Control option on the
shortcut menu.
 In the Format Control dialog box, which is subsequently displayed, enter the appropriate
cell reference(s).
 Click on the OK button.

If necessary, you can change the size and/or location of a control after placing it on a
worksheet. Simply select the control by holding down [CTRL] and by clicking on it.
Then drag any of the sizing handles that subsequently appear to resize the control,
or drag the actual control to reposition it. You can also delete a control by selecting
it and by pressing [DEL].

In this exercise, you will place a combo box and check box on a worksheet. You
will also link these controls to specific worksheet cells.

1. Make sure that all workbooks are closed. Then open the workbook named Order Processing.xls.
2. In the message box that appears (if your security level is set to Medium), click on the Enable
Macros button.
3. The worksheets in this workbook make up an order processing system. Click on the View/Enter
Sales Orders button to view the order information. (This table has been assigned the range name
OrderTable.)
4. Click on the Delivery Note Data button to display the delivery information. This is the area in
which you will place the combo and check boxes. The combo box will be used to select the delivery
method for the order, while the check box will be used to set its priority. The combo box will be linked
to a table containing the list items, as well as to the cell in which the selected item is to appear. The
check box will be linked to the cell in which the value of the box (TRUE or FALSE) is to appear.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Display the Forms toolbar. You will now create a list of delivery
methods.
©Copyright 2004 SVI Training Products, Inc. Page 3
Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments


2. In the range AD1:AD4, enter the
specified information into the
following cells:

AD1: Ace Couriers


AD2: Air Express
AD3: Parcel Post
AD4: COD
3. Assign the name DeliverBy to the The list is named.
range AD1:AD4.
4. Redisplay the area in which the You will now place a combo box on the
delivery information appears. worksheet.
5. Click on the Combo Box button on The button is selected, and the mouse
the Forms toolbar. pointer changes to a crosshair when it is
positioned in the worksheet.
6. Create the combo box by dragging When you are finished, the worksheet
the mouse pointer from the upper- should appear as illustrated below.
left corner of cell T7 to the lower-
right corner of cell U7.

7. Point to the combo box, and right- The Control panel of the Format Control
click the mouse button. Then click dialog box is displayed.
on Format Control on the shortcut
menu that appears.
8. Enter the specified information for When you are finished, the dialog box
the following options: should appear as illustrated below.

Input range: DeliverBy NOTE: In this case, the range DeliverBy


Cell link: V7 contains the options that are to appear in
Drop down lines: 4 the combo box, which will display four
lines when expanded. The number of the
selected option will appear in cell V7.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments

9. Choose the OK button. The dialog box is closed, and the control
is defined.
10. Click outside the combo box (in The box is expanded, and the list of
any blank area of the worksheet). delivery methods is displayed.
Then click on the down arrow at the
right side of the combo box.
11. Click on the second item in the list The selected option is displayed in the
(Air Express). combo box, and the number 2 appears in
cell V7.
12. Save the workbook. The changes are saved. You will now
place a check box on the worksheet.
13. Click on the Check Box button on The button is selected, and the mouse
the Forms toolbar. pointer changes to a crosshair when it is
positioned in the worksheet.
14. Create the check box by dragging When you are finished, the worksheet
the mouse pointer from the upper- should appear as illustrated below.
left corner of cell T9 to the lower-
right corner of cell U9.

©Copyright 2004 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments

15. Make sure that the check box is still The check box is relabeled.
selected.
Type: Urgent?
16. Point to the check box, and right- The Control panel of the Format Control
click the mouse button. Then click dialog box is redisplayed.
on Format Control on the shortcut
menu that appears.
17. Set the Cell link option to V9. When you are finished, the dialog box
should appear as illustrated on the
following page.

NOTE: In this case, the value of the


check box (TRUE or FALSE) will appear in
cell V9.

©Copyright 2004 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments

18. Choose the OK button. The dialog box is closed, and the control
is defined.
19. Click outside the check box (in any The box is checked, and TRUE is
blank area of the worksheet). Then displayed in cell V9.
click on the check box.
20. Click again on the check box. The box is unchecked, and FALSE is
displayed in cell V9.

NOTE: You can "hide" the entries in cells


V7 and V9 by resetting the font color to
white. (Notice that this has been done in
the illustration at the beginning of this
section.)
21. Save the workbook. The changes are saved. You will now set
up a delivery note that uses the
information in the new combo and check
boxes. You will begin by creating a
vertical lookup table.

©Copyright 2004 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments


22. Redisplay the area in which the list of The entries in the table are numbered.
delivery methods appears (the
range named DeliverBy). Then, in
the range AC1:AC4, enter the
numbers 1 through 4.
23. Assign the name LookupTable1 to The table is named.
the range AC1:AD4.
24. Redisplay the area in which the You will now create the delivery note.
delivery information appears.
NOTE: A view, named Delivery Note,
has been created to display the area in
which the delivery note is to appear.
Clicking on the Delivery Note button will
display this view.
25. Click on the Delivery Note button. The Delivery Note view is displayed.
26. Enter the labels shown in the Next, you will link cells in column T to
illustration below. data in the worksheet.

NOTE: Notice that the labels are


right-aligned.

©Copyright 2004 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments


27. Enter the specified When you are finished, the worksheet
formulas/functions into the should appear similar to that illustrated
following cells: below.

T32: =T3
T34: =VLOOKUP(T32,OrderTable,2)

NOTE: Apply the dd/mm/yy date format to the entry in cell T34.

T36: =VLOOKUP(T32,OrderTable,3)
T37: =VLOOKUP(T32,OrderTable,4)
T39: =VLOOKUP(T32,OrderTable,4)
T41: =VLOOKUP(V7,LookupTable1,2)
T43: =IF(V9=TRUE,"Urgent","Normal")

28. Save the workbook. The changes are saved.


29. Record a workbook macro, named Next, you will change the delivery
PrintDelNote, to print the range information.
R30:U43. Then add a macro
button to the worksheet to run the
macro.
30. Click on the Delivery Note Data
button (to return to that screen).
Change the entry in cell T3 to 3.
Expand the Delivery Method box,
and click on COD. Then click on the
Priority box (to select the option).

©Copyright 2004 SVI Training Products, Inc. Page 9


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

ACTION (You Do) COMPUTER RESPONSE / Comments


31. Click on the Delivery Note button. The delivery note is redisplayed. Notice
the new information that appears in the
note.
32. Save the workbook. The changes are saved.

1. With Sheet2 of Order Processing.xls displayed, enter the right-aligned label Item: in cell S45.

2. In cell T45, enter a VLOOKUP function to display the appropriate item entry in the order table.

3. Enter the right-aligned label Quantity: in cell S47.

4. In cell T47, enter a VLOOKUP function to display the appropriate quantity entry in the order
table.

5. Save the workbook.

6. Close the workbook (unless you wish to continue with the optional further practice that follows).
Also, close the Forms toolbar if you close the workbook.

©Copyright 2004 SVI Training Products, Inc. Page 10


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

(Optional)

1. With Sheet2 of Order Processing.xls displayed, enter the bold label Invoice Data in cell AI1.

2. Increase the width of columns AJ and AK to 14.

3. Create a view, named Invoice Data, that displays this area of the worksheet.

To do this, choose the View, Custom Views command (with cell AI1 displayed in
the upper-left corner of the Workbook window and the cell pointer located in cell
AI2). In the Custom Views dialog box, click on the Add button. Then, in the Add
View dialog box, enter the view name, and choose the OK button.

4. Display the Contents screen, and record a workbook macro, named GoToInvData, to display
the Invoice Data view.

5. Redisplay the Contents screen, and add a macro button to run the above macro.

6. Click on the macro button to display the Invoice Data view.

7. Save the workbook.

8. Set up the invoice data layout by entering the labels illustrated below.

©Copyright 2004 SVI Training Products, Inc. Page 11


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

9. In cell AK3, enter the formula =T3.

10. In cell AK4, enter a VLOOKUP function to display the order date. (Apply the dd/mm/yy date
format to the entry.)

11. In cell AK5, enter a VLOOKUP function to display the client name. (Right-align the entry in
this cell.)

12. In the range AU1:AU4, enter the specified information into the following cells:

AU1: COD
AU2: By Check
AU3: By Credit Card
AU4: By Bank Transfer

13. Assign the name PayBy to the range AU1:AU4.

14. In the range AT1:AT4, enter the numbers 1 through 4.

15. Assign the name LookupTable2 to the range AT1:AU4.

16. In the range AK7:AL7, place a combo box. Specify the payment table (PayBy) as the input
range and cell AM7 as the cell link.

17. In the range AK9:AL9, place a check box. Change the check box label to Paid?, and specify
cell AM9 as the cell link.

18. Save the workbook.

19. Set up the invoice layout by entering the labels illustrated on the following page.

©Copyright 2004 SVI Training Products, Inc. Page 12


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

20. Enter the necessary formulas/functions to display the invoice information in column AK.
(Apply the appropriate formatting to the Order Date and Price entries.)

21. Record a workbook macro, named PrintInvoice, to print the invoice.

22. Add a macro button next to the invoice to run:

a) The PrintInvoice macro

b) The GoToContents macro

23. Save the workbook, and then test your work.

24. Close the workbook, saving any changes. Also, close the Forms toolbar.

©Copyright 2004 SVI Training Products, Inc. Page 13


Excel 2003 Macros Section 6 - Placing Controls on a Worksheet

6.3 Summary

In this section, you have learned how to:

 Place a combo box on a worksheet. Use the Combo Box button (on the
Forms toolbar).

 Place a check box on a worksheet. Use the Check Box button (on the Forms
toolbar).

 Link a control to worksheet data. Use the Format, Control command or


the Format Control option on the
shortcut menu.

©Copyright 2004 SVI Training Products, Inc. Page 14


SECTION 7

USING VISUAL BASIC


TO WRITE MACROS

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7 USING VISUAL BASIC TO WRITE MACROS


7.1 Introduction

It is assumed that you are now familiar with the methods for recording and editing
macro instructions. In this section, you will take the next step and write your own
macros "from scratch." This will not only expand your knowledge of the Visual Basic
programming language, it will greatly increase the capabilities of your macros.

In this section, you will learn how to:

 Open a new module in the Visual Basic Editor.

 Display a data prompt during macro execution.

 Use a conditional statement in a macro.

 Use a control loop in a macro.

When you open a workbook in this section (and in subsequent sections), a message
box may appear, depending on your current security level setting. This course
assumes that your security level is set to Medium. When this security level is in
effect and you open a workbook containing one or more macros, Excel displays a
message box regarding macro viruses, allowing you to enable or disable the macros
in that workbook. To reset the security level, choose the Tools, Macros, Security
command, select the new security level in the Security dialog box, and click on the
OK button.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.2 Opening a New Module in the Visual Basic Editor

The first step in writing a macro is that of creating the module in which the
instructions are to be stored.

To open a new module in the Visual Basic Editor:

 Choose the Tools, Macro, Macros command.

 In the Macro dialog box, which is subsequently displayed, enter a name for the macro.

 Click on the Create button.

In this exercise, you will open a new module in the Visual Basic Editor.

1. Make sure that all workbooks are closed. Then open the workbook named Growth Model.xls.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Macro dialog box is displayed.
followed by Macros.
2. Type: GetData The macro name is entered.
3. Choose the Create button. The Microsoft Visual Basic window is
displayed (as illustrated on the following
page). Notice that a new module
containing only a Sub statement and End
Sub statement appears in this window.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.3 Displaying a Data Prompt During Macro Execution

The InputBox function is used to prompt the user for data input during the execution
of a macro. The user's subsequent response is then entered into a specific cell.

Input Box with a Data Prompt

In this exercise, you will write a macro that displays three data prompts and
enters the responses to these prompts into specific cells.

1. Make sure that a new module appears in the Microsoft Visual Basic window.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. In the Microsoft Visual Basic window, These instructions are explained in the
insert the comments and notes that follow the exercise.
instructions indicated on the
following page (those in bold type).

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

Sub GetData( )
'
' This macro displays prompts for three variables -- Region, Year1 and
' Growth -- and enters the responses into the range C3:C5.
'
Range("C3").Select
Region = InputBox("Enter Name of Region")
ActiveCell.FormulaR1C1 = Region
Range("C4").Select
Year1 = InputBox("Enter Sales Volume for First Year")
ActiveCell.FormulaR1C1 = Year1
Range("C5").Select
Growth = InputBox("Enter Growth Rate", _
Default:=0.05)
ActiveCell.FormulaR1C1 = Growth
End Sub

2. Click on the Save Growth The workbook is saved.


Model.xls button on the Standard
toolbar.
3. Click on the Close button on the Title The Visual Basic Editor is closed, and the
bar of the Microsoft Visual Basic Workbook window is redisplayed.
window.
4. Run the macro you have just You are prompted for the region name.
created (GetData).
5. Type: Central The region name is entered into cell C3,
Press [ENTER]. and you are prompted for the first year's
sales volume.
6. Type: 5500 The sales volume is entered into cell C4,
Press [ENTER]. and you are prompted for the growth
rate. You will accept the default of 5%.
7. Press [ENTER]. The growth rate is entered into cell C5.
The worksheet should now appear as
illustrated on the following page.

©Copyright 2004 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

8. Save the workbook, and then close The changes are saved, and the
it. worksheet is cleared from the screen.

©Copyright 2004 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

1. The Sub GetData( ) statement of the preceding macro defines the macro name. The macro, of
course, ends with an End Sub statement.

2. The next four lines are comments. It is a good idea to include comments to explain the purpose of
a macro and/or to help the user understand what a particular instruction or series of instructions
accomplishes.

3. The next instruction selects cell C3 in whatever worksheet is current when the macro is run.

4. The next instruction displays an input box that prompts the user for the region name. It also
defines a variable, named Region, for holding the response.

5. The next instruction enters the user's response into the active cell (C3).

6. The next three instructions repeat the above procedure, this time defining a variable named Year1
and displaying an input box that prompts the user for the first year's sales volume. (The response, in
this case, is entered into cell C4.)

7. The next three instructions repeat the same procedure, this time defining a variable named
Growth and displaying an input box that prompts the user for the growth rate. (The response, in this
case, is entered into cell C5.) The InputBox function in this group specifies the default value that is to
appear in the input box (0.05). Notice the underscore (_) at the end of the second line. This is used to
extend the instruction to the next line.

©Copyright 2004 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

1. Open the workbook named Investment Plan.xls.

2. Create a macro, named GetInfo, that prompts the user for the following (and enters the user's
response into the appropriate cell):

a) The client name

b) The amount of each investment

c) The number of payments per year, with 12 being the default

3. Save the workbook.

4. Run the macro.

5. Save the workbook once again, and then close it.

©Copyright 2004 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.4 Using a Conditional Statement in a Macro

Visual Basic includes several statements to control the flow of macro execution.
The If . . . Then statement allows you to include one or more operations in a macro
that are performed only when a certain condition is true. It is useful for such
purposes as:

 Displaying a warning message when user response seems unusual.

 Offering the user the option of performing a certain operation (for example, that of
printing the current worksheet and/or saving the current workbook).

If (Condition) Then
(Instruction or
instructions
to be executed)
End If
Structure of an If . . . Then Statement

An If . . . Then statement often includes a MsgBox function, which is a convenient


method for displaying messages and for obtaining user input.

Message Box with a Warning

The If . . . Then statement can include an optional Else clause, which includes one or
more alternate operations that are to performed when the condition is false.

©Copyright 2004 SVI Training Products, Inc. Page 9


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

In this exercise, you will use a conditional statement in a macro. Specifically,


you will enter two If . . . Then statements -- one to display a warning message if
the user response exceeds a certain value and one to offer the user the option of
printing the worksheet. A MsgBox function will be included in each statement --
first to display the warning message and then to display the print option prompt.

1. Make sure that the Workbook window is clear. Then open the workbook named Growth
Model.xls.

2. In the message box that appears (if your security level is set to Medium), click on the Enable
Macros button.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Macro dialog box is displayed.
followed by Macros.
2. In the list of macros, click on The instructions of the GetData macro
GetData. Then click on the Edit are displayed in the Microsoft Visual
button. Basic window.
3. At the end of the macro (just before These instructions are explained in the
the End Sub statement), insert the notes that follow the exercise.
instructions indicated on the
following page.

NOTE: The indentation of the If . . .


Then statement instructions is
optional. It is used here to set off the
instructions, thereby making the
macro easier to read and
understand.

©Copyright 2004 SVI Training Products, Inc. Page 10


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

If Growth > 0.2 Then


MsgBox ("Warning! Growth seems rather high!")
End If
Response = MsgBox ("Do you want to print this?", _
vbYesNo, "Question")
If Response = vbYes Then
Range("A1:F16").Select
Selection.PrintOut
Range("D1").Select
End If

4. Click on the Save Growth The workbook is saved.


Model.xls button.
5. Close the Visual Basic Editor, and
redisplay the Workbook window.
6. Run the macro (GetData). When A warning message is displayed.
prompted, enter Northern as the
region name, 5000 as the first year's
sales volume, and .4 as the growth
rate.
7. Choose the OK button. The input is accepted, and a second
message box is displayed (as illustrated
below).

8. Choose the Yes button. The worksheet is printed.


9. Save the workbook, and then close The changes are saved, and the
it. worksheet is cleared from the screen.

©Copyright 2004 SVI Training Products, Inc. Page 11


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

1. The If Growth > 0.2 Then statement in the preceding macro instructions tests for a growth rate of
more than 20%. If the rate exceeds this value, the MsgBox function is executed, and a basic message
box with an OK button is displayed.

2. The first End If statement marks the end of the first If . . . Then statement.

3. The next instruction defines a variable, named Response, and displays a message box. The
MsgBox function in this instruction, like the first MsgBox function, specifies the message that is to
appear in the box. In addition, it specifies the buttons that are to be displayed (Yes and No) and the
box title. The buttons argument can be specified by entering the appropriate text constant (as in this
macro) or by entering the equivalent numeric constant. (The argument, in this case, could also appear
as the number 4, the numeric equivalent of vbYesNo.)

4. The next If Response = vbYes Then statement tests the user's response (in the variable Response).
If the Yes button was selected, the worksheet range A1:F16 is printed. (This instruction could also be
entered as If Response = 6 Then since the number 6 is the numeric equivalent of vbYes.)

5. The second End If statement marks the end of the second If . . . Then statement.

1. Open the workbook named Investment Plan.xls.

2. Insert the appropriate instructions into the GetInfo macro to:

a) Display a warning message if more than 12 payments per year are


specified.

b) Display a message box giving the user the option of printing the worksheet.
(If the response is Yes, the range A1:H14 should be printed.)

3. Save the workbook.

4. Run the revised macro.

5. Save the workbook once again, and then close it.

©Copyright 2004 SVI Training Products, Inc. Page 12


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.5 Using a Control Loop in a Macro

Do . . . Loop and For . . . Next are two additional statements for controlling the
flow of macro execution. Both allow you to create macros in which operations are
"looped" -- that is, repeated a certain number of times.

The Do . . . Loop statement repeats an instruction or set of instructions while or until


a specific condition is true, depending on whether While or Until is included in the
statement. It is used, for example, to ensure that user response falls within a specific
range of entries.

Do While/Until (Condition)
(Instruction or
instructions
to be executed)
Loop
Structure of a Do . . . Loop Statement

The For . . . Next statement, on the other hand, repeats an instruction or set of
instructions a specific number of times. It is used, for example, to repeatedly prompt
the user for a finite number of entries.

For (Counter Variable) = (Starting Value) To (Ending


Value)
(Instruction or instructions
to be executed)
Next (Counter Variable)
Structure of a For . . . Next Statement

©Copyright 2004 SVI Training Products, Inc. Page 13


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

In this exercise, you will use control loops in a macro. Specifically, you will enter
1) a Do . . . Loop statement to prompt the user for a single value and test the
response, and 2) a For . . . Next statement to prompt the user for four values.

1. Make sure that the Workbook window is clear. Then open the workbook named Sales
Forecast.xls.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Macro dialog box is displayed.
followed by Macros.
2. Type: UpdateSheet A new module is opened in the Visual
Choose the Create button. Basic Editor.
3. In the Microsoft Visual Basic window, These instructions are explained in the
insert the instructions indicated on notes that follow the exercise.
the following page (those in bold
type).

©Copyright 2004 SVI Training Products, Inc. Page 14


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

Sub UpdateSheet( )
Range("B3").Select
InflationRate = 0
Do While InflationRate < 0.01 Or InflationRate > 0.2
Beep
InflationRate = InputBox("Enter Inflation Rate (.01 to .2):")
Loop
ActiveCell.FormulaR1C1 = InflationRate
Range("B6").Select
Beep
SalesVol = InputBox("Enter Sales Volume for First Period:")
ActiveCell.FormulaR1C1 = SalesVol
For N = 1 To 4
Beep
ActiveCell.Offset(0, 1).Range("A1").Select
SalesVol = InputBox("Enter Sales Volume for Next Period:", _
, , 50, 150)
ActiveCell.FormulaR1C1 = SalesVol
Next N
Range("C1").Select
End Sub

4. Click on the Save Sales The workbook is saved.


Forecast.xls button on the Standard
toolbar.
5. Close the Visual Basic Editor, and
redisplay the Workbook window.
6. Run the macro (UpdateSheet). You are prompted for the inflation rate.
7. Type: .0075 Since you entered a value less than .01,
Press [ENTER]. you are prompted again for the inflation
rate.
8. Type: .25 Since you entered a value greater than .
Press [ENTER]. 2, you are prompted once again for the
inflation rate.
9. Type: .05 The inflation rate is accepted, and you
Press [ENTER]. are prompted for the sales volume for
the first period.
10. Type: 6000 You are prompted for the sales volume
Press [ENTER]. for the next period.

©Copyright 2004 SVI Training Products, Inc. Page 15


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


11. Enter the following sales figures, When you are finished, the worksheet
(pressing [ENTER] after typing each): should appear as illustrated below.

6500
7000
7500
8000

12. Save the workbook, and then close The changes are saved, and the
it. worksheet is cleared from the screen.

©Copyright 2004 SVI Training Products, Inc. Page 16


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

1. The third line of the preceding macro sets a variable, named InflationRate, to an initial value of
zero.

2. The Do While InflationRate < 0.01 Or InflationRate > 0.2 statement repeatedly prompts the
user for an inflation rate until the response is within the range .01 to .2. The Beep statement causes the
computer to sound a "beep."

3. The For N = 1 To 4 statement executes the following four instructions four times. N, in this case,
is a user-defined variable that serves as a counter. (The variable could have been given any other
appropriate name.)

4. The InputBox function in the For . . . Next statement is slightly different from other InputBox
functions you have seen. Notice that three commas follow the prompt. The second and third commas
are placeholders for two parameters (the title and default value for the box), which, in this case, are not
specified. The numbers 50 and 150 define the position of the box, from the left side and from the top
of the screen, respectively, ensuring that the input box will not obscure the relevant part of the
worksheet.

1. Open the workbook named Employee Sales.xls.

2. Create a macro, named UpdateFile, that:

a) Prompts the user for the month number, repeating the prompt until the
response is between 1 and 12.

b) Enters the user's response into cell C3.

c) In turn, prompts the user for the monthly sales for each individual listed
and enters the user's response into the appropriate cell. (Make sure that the
input box does not cover the relevant part of columns A or B.)

d) Displays a message box giving the user the option of printing the
worksheet. (If the response is Yes, the range A1:C14 should be printed.)

©Copyright 2004 SVI Training Products, Inc. Page 17


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

3. Save the workbook.

4. Run the macro.

5. Save the workbook once again, and then close it.

©Copyright 2004 SVI Training Products, Inc. Page 18


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.6 Additional Control Statements

This subsection is included for reference purposes.

In this section, you were introduced to three statements for controlling the flow of
macro execution -- If . . . Then ( . . . Else), Do . . . Loop and For . . . Next.

Excel also provides the following macro control statements:

Select Case This statement executes one of two or more sets of instructions,
depending on the value of an expression. It can be used, for example,
to print one of several blocks of text, depending on user response to a
prompt.

GoTo This statement unconditionally branches to a specific instruction within


the current procedure. It can be used in an If . . . Then or If . . . Then . .
. Else statement, for example, to jump to a particular location in a
macro, depending on whether the tested condition is true or false.

For more information about these statements, see the Visual Basic Help system.

©Copyright 2004 SVI Training Products, Inc. Page 19


Excel 2003 Macros Section 7 - Using Visual Basic to Write Macros

7.7 Summary

In this section, you have learned how to:

 Open a new module in the Visual Use the Tools, Macro, Macros
Basic Editor. command and the Create button
in the Macro dialog box.

 Display a data prompt during Use the InputBox function.


macro execution.

 Use a conditional statement in a Enter an If . . . Then statement and a


macro. MsgBox function.

 Use a control loop in a macro. Enter a Do . . . Loop statement and/or a


For . . . Next statement.

©Copyright 2004 SVI Training Products, Inc. Page 20


SECTION 8

CREATING AND
USING WORKBOOK
MACROS

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

8 CREATING AND USING WORKBOOK MACROS


8.1 Introduction

This section discusses the methods for creating and using workbook macros. In
it, you will learn how to:

 Record a workbook macro.

 Run a workbook macro.

 Add a macro button to a worksheet.

©Copyright 2003 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

8.2 Recording and Running a Workbook Macro

A workbook macro is associated with a specific workbook and is used for


performing special-purpose operations. While a personal macro can be used in any
worksheet at any time, a workbook macro can be used only in the worksheets of its
associated workbook and only when that workbook is open.

The methods for recording and running a workbook macro are essentially the same
as those for recording and running a personal macro. When recording a workbook
macro, however, you must select either the This Workbook option, or the New
Workbook option (in the Record Macro dialog box), to let the program know that you
wish to store the macro in either the current workbook, or a new workbook, instead of
the Personal Macro Workbook.

In this exercise, you will record three workbook macros that display various
sections of a worksheet. You will examine the instructions of these macros
and then run the macros.

1. Make sure that all workbooks are closed. Then open the workbook named Regional Sales
Report.xls.

Sheet1 of this workbook includes three views (North Region, South Region and
Contents), which can be used to navigate through the worksheet. (A view is a
specific section of a worksheet that has been defined with the View, Custom
Views command.)

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Record Macro dialog box is
followed by Record New Macro. displayed.
2. Type: GoToNorth The macro name is entered.
3. Expand the Store macro in box, The Macro Recorder is turned on.
and click on This Workbook (unless
that option already appears in the
Store macro in box). Then click on
the OK button.

©Copyright 2003 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


4. Choose the View, Custom Views The Custom Views dialog box is displayed
command. (as illustrated below).

5. In the list of views, click on North The dialog box is closed, and the North
Region. Then click on the Show Region view is displayed.
button.
6. Click on the Stop Recording button. The Macro Recorder is turned off.
7. Using a procedure similar to that
described above, record a second
macro, named GoToSouth, to
display the South Region view.
Make sure that the Macro Recorder is
turned off when you are finished.
8. Using a similar procedure, record a
third macro, named GoToContents,
to display the Contents view. Make
sure that the Macro Recorder is
turned off when you are finished.
9. Save the workbook. You will now display the instructions of
the macros you have recorded.
10. Press [ALT] + [F8]. The Macro dialog box is displayed.

NOTE: [ALT] + [F8] is a shortcut method


for displaying the Macro dialog box.
11. In the list of macros, click on The dialog box is closed, and the
GoToNorth. Then click on the Edit instructions of the GoToNorth, GoToSouth
button. and GoToContents macros are displayed
in the Visual Basic Editor (as illustrated
on the following page).

©Copyright 2003 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

12. Close the Visual Basic Editor. The Workbook window is redisplayed.
13. Using the Tools, Macro, Macros When you are finished, make sure that
command (or the [ALT] + [F8] the Workbook Contents screen is
keyboard shortcut), run the three displayed.
macros you have recorded
(GoToNorth, GoToSouth and
GoToContents).

©Copyright 2003 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

8.3 Adding a Macro Button to a Worksheet

A macro, as you know, can be run via the menu system or via a shortcut key
combination. You can also assign a macro to a button on a worksheet and then use
that button to run the macro.

Macro Buttons

To add a macro button to a worksheet:

 Display the Forms toolbar, and select the Button tool.

 Create the macro button by dragging the mouse pointer.

 In the Assign Macro dialog box, which is displayed when you release the mouse button,
select the name of the macro that is to be associated with the button.

 Click on the OK button.

 With the button selected, type a label for the button.

Button Tool

©Copyright 2003 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

If necessary, you can change the size and/or location of a macro button after adding
it to a worksheet. Simply select the button by holding down [CTRL] and by clicking
on it. Then drag any of the sizing handles that appear to resize the button, or
drag the border of the button to reposition it. You can also delete a button by
selecting it and by pressing [DEL].

In this exercise, you will add macro buttons to the current worksheet to run
the GoToNorth and GoToSouth macros.

1. Make sure that Regional Sales Report.xls is still open and that cell A1 (of Sheet1) is selected.

You will begin by displaying the Forms toolbar.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Point to any toolbar, and right-click The Forms toolbar is displayed (as
the mouse button. Then click on illustrated on the following page). You
Forms on the shortcut menu that will now create a button to run the
appears. GoToNorth macro.

©Copyright 2003 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

2. Click on the Button tool on the The tool is selected, and the mouse
Forms toolbar. pointer changes to a crosshair when it is
positioned in the worksheet.
3. Point to the upper-left corner of A button (with the default text "Button
cell D5. Press and hold down the 1") is drawn, and the Assign Macro dialog
mouse button, and drag the mouse box is displayed (as illustrated below).
pointer to the lower-right corner of
cell E6. Then release the mouse
button.

©Copyright 2003 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


4. In the list of macros, double-click on The dialog box is closed, and the
GoToNorth. GoToNorth macro is assigned to the
button.
5. Make sure that the button is still The new button label replaces the default
selected (surrounded by sizing label. You will now create an identically-
handles). shaped button to run the GoToSouth
Type: View North Region macro.
Then click outside the button
(within the worksheet).
6. Press and hold down [CTRL], and The button is selected.
click on the button. Then release
[CTRL].
7. Click on the Copy button. Then click A copy of the button is displayed.
on the Paste button.
8. Point to the border of the second The button is repositioned.
button. Then drag the button to
the range D9:E10.
9. Make sure that the second button The Assign Macro dialog box is
is still selected. Point to its border, redisplayed.
and right-click the mouse button.
Then click on Assign Macro on the
shortcut menu that appears.
10. In the list of macros, double-click on The dialog box is closed, and the
GoToSouth. GoToSouth macro is assigned to the
button.
11. Make sure that the second button The new button label replaces the default
is still selected. label.
Type: View South Region
Then click outside the button
(within the worksheet).
12. Save the workbook. The changes are saved. You will now test
the macro buttons.
13. Click on the View North Region Data for the North Region is displayed.
button.
14. Press [CTRL] + [HOME]. The Workbook Contents screen is
redisplayed.
15. Click on the View South Region Data for the South Region is displayed.
button.
16. Press [CTRL] + [HOME]. The Workbook Contents screen is
redisplayed.

©Copyright 2003 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

1. With Regional Sales Report.xls open, display the data for the North Region. In an appropriate
area, add two macro buttons -- one to run the GoToSouth macro and one to run the GoToContents
macro.

2. Display the data for the South Region. In an appropriate area, add two macro buttons -- one to
run the GoToNorth macro and one to run the GoToContents macro.

3. Test the new buttons you have added.

4. Display the Workbook Contents screen. Record a workbook macro, named SaveBook, to save
the workbook.

5. Add a macro button to the Workbook Contents screen to run this macro.

6. Record a workbook macro, named PrintNorth, to print the data for the North Region.

7. Add a macro button to the North Region screen to run this macro.

8. Record a workbook macro, named PrintSouth, to print the data for the South Region.

9. Add a macro button to the South Region screen to run this macro.

10. Run the PrintNorth and PrintSouth macros by using the associated macro buttons.

11. Display the Workbook Contents screen, and save the workbook by using the appropriate macro
button.

12. Close the workbook (unless you wish to continue with the optional further practice that follows).
Also, close the Forms toolbar if you close the workbook.

(Optional)

1. With Regional Sales Report.xls open, record a workbook macro, named FormatDollar, to
apply the Currency with 0 decimal places format to the numeric data in both tables. Optionally,
assign a suitable keyboard shortcut to the macro.

2. Record a workbook macro, named FormatComma, to apply the Comma with 0 decimal
places format to the numeric data in both tables. Optionally, assign a suitable keyboard shortcut to
the macro.

3. Run both macros.

©Copyright 2003 SVI Training Products, Inc. Page 9


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

4. Save the workbook, and then close it.

5. Close the Forms toolbar.

©Copyright 2003 SVI Training Products, Inc. Page 10


Excel 2003 Macros Section 8 - Creating and Using Workbook Macros

8.4 Summary

In this section, you have learned how to:

 Record a workbook macro. Use the Tools, Macro, Record New


Macro command, and the This
Workbook or New Workbook option in
the Record Macro dialog box.

 Run a workbook macro. Use the methods for running a personal


macro.

 Add a macro button to a Use the Button tool (on the Forms
worksheet. toolbar).

©Copyright 2003 SVI Training Products, Inc. Page 11


SECTION 9

CREATING AND
USING PERSONAL
MACROS

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9 CREATING AND USING PERSONAL MACROS


9.1 Introduction

This section begins by describing the two types of Excel macros. It then discusses
the methods for creating and using personal macros. In this section, you will
learn how to:

 Record a personal macro.

 Run a personal macro.

 Display macro instructions.

 Edit a macro.

 Include relative cell references in a macro.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.2 What is a Macro?

A macro is a sequence of keystrokes and/or mouse actions that are stored in a


workbook as a series of instructions. When a macro is executed (run), the associated
operations are carried out automatically, saving you the time it would take to
manually perform the same operations.

With Excel, you can create two types of macros:

Personal This type of macro is stored in a hidden Personal Macro Workbook,


which is opened automatically when you start the program. Thus, it is
available in all worksheets. Personal macros are generally used for
such purposes as setting up a basic worksheet structure, applying
common formatting to worksheet entries, and setting frequently-used
print options and printing a worksheet.

Workbook This type of macro is stored in a specific workbook. Thus, it is available


only in the worksheets of that workbook. Workbook macros are
generally used for such purposes as entering custom labels into a
worksheet, formatting a specific area of a worksheet, and printing
selected worksheet entries.

This section, as mentioned earlier, discusses personal macros.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.3 Recording a Personal Macro

The easiest way to create any type of macro is to use Excel's Macro Recorder to
record the various operations.

To record a personal macro:

 Choose the Tools, Macro, Record New Macro command.

 In the Record Macro dialog box, which is subsequently displayed, enter a name for the
macro. (See the second note below.)

 Optionally, specify a shortcut key (which can be used in combination with [CTRL] to run
the macro) and/or edit the default description.

 In the Store macro in box, select the Personal Macro Workbook option, if necessary.

 Click on the OK button to turn on the Macro Recorder.

 Perform the operations that are to be included in the macro.

 When you are finished, click on the Stop Recording button on the Stop Recording
toolbar.

1. You can also use the Record Macro button on the Visual Basic toolbar to display the Record
Macro dialog box (mentioned above).

2. A macro name can include letters, numbers and underscores. The first character, however, must be
a letter. (The name should not be the same as a cell reference.) Although spaces are not allowed, the
underscore character can be used to create multiple-word macro names (for example, Make_Sales). In
this course, however, you will use one-word macro names (for example, MakeSales).

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

In this exercise, you will record a personal macro that enters labels and
formulas into a worksheet.

1. If necessary, turn on your computer system, and load Windows.

2. If you are using a data diskette (instead of storing the course data files on the hard disk), insert that
diskette into the appropriate drive. Then start Excel.

3. If necessary, reset the working folder with the Tools, Options command.

4. Make sure that a blank worksheet is displayed. (Close the Getting Started task pane if it is
displayed.)

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Record Macro dialog box is
followed by Record New Macro. displayed. (An example of this dialog
box is illustrated below.)

2. Type: MakeSales The macro name is entered.

NOTE: Make sure that you enter the


above as one word since spaces are
not allowed in a macro name.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


3. Press [TAB] (to move to the The shortcut key combination ([CTRL] +
Shortcut key box). [m]) will provide an alternate method for
Type: m running the macro.

NOTE: Make sure that you enter the


above letter (m) as a lowercase
character.
4. Expand the Store macro in box, The macro will be stored in the Personal
and click on Personal Macro Macro Workbook. The dialog box should
Workbook (unless that option now appear similar to that illustrated
already appears in the Store macro in below. (The description information, of
box). course, will no doubt be different.)

5. Click on the OK button. The dialog box is closed, and the


message "Recording" is displayed on the
Status bar. You will now record the
operations that are to be included in the
macro.

NOTE: Notice the Stop Recording


toolbar, which displays two buttons --
Stop Recording (to turn off the Macro
Recorder) and Relative Reference
(which is discussed later in this section).
If this toolbar obscures the text area, you
can move it to another area of the screen
by dragging its Title bar.
6. Make sure that cell A1 is selected. The worksheet title is entered.
Type: Sales Data
Press [ENTER].

©Copyright 2004 SVI Training Products, Inc. Page 5


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


7. Reselect cell A1. Using the Bold The title is reformatted.
button, bold the text of the label.
Then, using the Font Size box, reset
the font size of the label to 14.
8. Select cell B3. A column label is entered.
Type: Week 1
Press [ENTER].
9. Reselect cell B3. Then, using the The label is reformatted.
Italic and Center buttons, italicize
and center the text of the label.
10. Using AutoFill, fill the range C3:E3 Additional column labels are entered.
(with Week 2, Week 3 and Week 4).
11. Select cell A4. The name is entered, and the cell pointer
Type: Jim Johnson moves to cell A5.
Press [ENTER].
12. Enter the specified names and label
into the following cells:

Cell A5: Mary Moore


Cell A6: Steve Sullivan
Cell A7: Polly Potter
Cell A8: Bill Brown
Cell A9: Total
13. Reselect cell A9. Then, using the
Bold button, bold the text of the
label (Total).
14. Using your mouse, increase the
width of column A so that all names
are displayed within that column.
15. Select cell B9. The formula is entered. The result, of
Type: =SUM(B4:B8) course, is currently 0 since no data has
Press [ENTER]. been entered into the range B4:B8.

NOTE: Function names and cell


references can be entered in
uppercase characters (as indicated
above) or in lowercase characters --
for example, =sum(b4:b8).

©Copyright 2004 SVI Training Products, Inc. Page 6


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


16. Reselect cell B9. Then, using The formula is copied into columns C
AutoFill, copy the formula into the through E.
range C9:E9.
17. Select cell C1. Then click on the The cell pointer is repositioned, and the
Bold button. worksheet is now complete. It should
appear as illustrated below.

NOTE: In this case, any characters


entered into cell C1 will be bolded.

18. Click on the Stop Recording button. The Macro Recorder is turned off.

19. Close the workbook, without


saving it.

©Copyright 2004 SVI Training Products, Inc. Page 7


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

1. In the previous exercise, you assigned the keyboard shortcut [CTRL] + [m] to the macro by
entering the lowercase "m" in the Record Macro dialog box. You can, however, run the macro by
pressing either the lowercase or uppercase key (for example, [CTRL] + [m] or [CTRL] + [M]).

2. You can also assign a keyboard shortcut in the form of [CTRL] + [SHIFT] + [Letter] by entering
an uppercase letter in the Record Macro dialog box. In this case, the macro can be run by pressing
either the lowercase or uppercase letter (for example, [CTRL] + [SHIFT] + [m] or [CTRL] + [SHIFT]
+ [M]).

3. When assigning a keyboard shortcut to a macro, you should avoid using keys that are currently
assigned to specific Excel operations (for example, [CTRL] + [S], the shortcut for saving a workbook)
since the new shortcut will override the existing shortcut as long as the workbook containing the macro
is open.

©Copyright 2004 SVI Training Products, Inc. Page 8


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.4 Running a Personal Macro

You will now run the macro created in the last subsection.

To run a personal macro:

 Choose the Tools, Macro, Macros command.

 In the Macro dialog box, which is subsequently displayed, select the macro name.

 Click on the Run button.

OR

 Simply press the assigned shortcut key combination (if one has been assigned).

You can also use the Run Macro button on the Visual Basic toolbar to display the
Macro dialog box (mentioned above).

In this exercise, you will run the macro created in the last exercise. You will
perform the operation twice -- first by using the menu system and then by using the
assigned shortcut key combination.

1. Make sure that the Workbook window is clear. Then open a new workbook.

You will begin by using the menu system to run the macro.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Macro dialog box is displayed (as
followed by Macros. illustrated on the following page).

©Copyright 2004 SVI Training Products, Inc. Page 9


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

2. Make sure that All Open The dialog box is closed, and the macro
Workbooks appears in the Macros is run. When the macro finishes its
in box and that PERSONAL.XLS! execution, the cell pointer should be
MakeSales is selected. Then click located in cell C1.
on the Run button.
3. Type: April A label is entered to identify the month of
Press [ENTER]. the report.
4. Display Sheet2. Cell A1 of Sheet2 should be selected.
You will now use the keyboard shortcut to
run the macro.
5. Press [CTRL] + [m]. The macro is run once again, this time in
Sheet2.
6. Make sure that cell C1 is selected. A label is entered to identify the month of
Type: May the second report.
Press [ENTER].
7. Save the workbook in a file named
Sales for April & May.xls.

©Copyright 2004 SVI Training Products, Inc. Page 10


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


8. Enter the following data into Notice that the totals are automatically
Sheet1: calculated in row 9.

Week 1: Week 2: Week 3: Week 4:

Jim Johnson: 500 650 700 750


Mary Moore: 340 480 590 720
Steve Sullivan: 270 290 310 330
Polly Potter: 480 540 680 790
Bill Brown: 500 360 420 450

9. Optionally, enter data of your choice


into Sheet2.
10. Save the workbook, and then close The changes are saved, and the
it. worksheets are cleared from the screen.

©Copyright 2004 SVI Training Products, Inc. Page 11


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

1. Record a personal macro, named MakeProfits, that sets up the worksheet illustrated below.
Assign the shortcut key combination [CTRL] + [t] to the macro.

Notice that the worksheet includes special number formatting, font changes and
borders. The range B9:F9 contains SUM functions to total the data in each
column. When the macro finishes its execution, the cell pointer should be located
in cell D1.

2. When you are finished, close the workbook, without saving it. Then open a new workbook.

3. Using the menu system, run the MakeProfits macro in Sheet1 of the workbook.

4. In cell D1 of Sheet1, enter the label USA.

5. Using the shortcut key combination, run the same macro in Sheet2 of the workbook.

6. In cell D1 of Sheet2, enter the label Europe.

7. Enter data of your choice into both worksheets.

8. Save the workbook in a file named Profit Summary.xls.

9. Close the workbook.

©Copyright 2004 SVI Training Products, Inc. Page 12


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.5 Displaying Macro Instructions

All Excel macros consist of a series of instructions written in the Microsoft Visual
Basic for Applications programming language (hereafter referred to as simply
"Visual Basic"). Although you do not need to know anything about this language to
record a macro, there may be times when you will want to modify one or more
operations performed by a particular macro. If you are familiar with Visual Basic, you
can make necessary modifications to a macro (without re-recording it) by displaying
and editing the macro instructions.

Macro Instructions

To examine the instructions of a specific personal macro, you must first open (unhide)
the Personal Macro Workbook (Personal.xls).

To unhide the Personal Macro Workbook:

 Choose the Window, Unhide command.

 In the Unhide dialog box, which is subsequently displayed, select the PERSONAL.XLS
(or PERSONAL) option, if necessary.

 Click on the OK button.

©Copyright 2004 SVI Training Products, Inc. Page 13


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

When you are finished working in the Personal Macro Workbook, you should once
again hide it by choosing the Window, Hide command. Also, when you exit from
Excel and are asked if you would like to save the changes to the Personal Macro
Workbook, you should select the Yes option. Otherwise, the Personal Macro
Workbook will appear automatically the next time you start Excel.

Once you have opened the Personal Macro Workbook, you can display the desired
macro instructions in the Visual Basic Editor.

To open the Visual Basic Editor (and display the instructions of a specific
macro):

 Choose the Tools, Macro, Macros command.

 In the Macro dialog box, which is subsequently displayed, select the macro name.

 Click on the Edit button.

You can also use the Tools, Macro, Visual Basic Editor command or the Visual
Basic Editor button on the Visual Basic toolbar to open the Visual Basic Editor.

©Copyright 2004 SVI Training Products, Inc. Page 14


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

In this exercise, you will unhide the Personal Macro Workbook. You will then
print and examine the various instructions of your MakeSales macro.

1. Make sure that the Workbook window is clear.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Window, Unhide The Unhide dialog box is displayed (as
command. illustrated below).

2. Make sure that PERSONAL.XLS (or The dialog box is closed, and the
PERSONAL) is selected. Then click Personal Macro Workbook is opened. You
on the OK button. will now open the Visual Basic Editor.

NOTE: File extensions may or may


not appear on your screen.
3. Choose the Tools, Macro command, The Macro dialog box is displayed.
followed by Macros.

©Copyright 2004 SVI Training Products, Inc. Page 15


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


4. Click on MakeSales. Then click on The dialog box is closed, and the macro
the Edit button. instructions are displayed in the Visual
Basic Editor (the Microsoft Visual Basic
window).

NOTE: The Microsoft Visual Basic


window includes one or more smaller
windows. The macro instructions appear
in the Code window. (If this window is
not maximized, you can increase its size
by clicking on the Maximize button on
the Title bar.) The Microsoft Visual Basic
window may also display a Project
Explorer window and a Properties
window. (Since you will not use the
Project Explorer and Properties windows
in this section, you may wish to close
them, if they are currently displayed, by
clicking on the Close button on the Title
bar of each.)
5. Select the instructions of the
MakeSales macro by dragging the
mouse pointer from the beginning
of the first instruction, Sub
MakeSales (), to the end of the last
instruction, End Sub (immediately
above the first instruction of the
MakeProfits macro).
6. Choose the File, Print command. The macro instructions are printed.
Then click on the OK button in the
Print dialog box.

©Copyright 2004 SVI Training Products, Inc. Page 16


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


7. Examine the macro instructions.
In particular, note the following:
Comments Lines beginning with an apostrophe are comments. These lines
are not actual instructions, but are used to identify the
individual who created the macro and the date the macro was
recorded. Comments can also be used to explain the purpose
of the macro or, in some cases, to help the user understand
what a particular instruction or group of instructions
accomplishes.
Sub . . . A macro is made up of one or more procedures. Sub, the
most
End Sub common type of procedure, begins with a Sub . . . statement
and ends with an End Sub statement.
ActiveCell . . . This can appear in many different forms. In the MakeSales
macro, for example, it appears as ActiveCell.FormulaR1C1
and is used to specify the contents (entry) of a particular cell.
Range . . . Select This is used to select a specific cell and often appears in
combination with ActiveCell. In the MakeSales macro, for
example, the following lines select cell B3 and enter the label
Week 1 into that cell:
Range("B3").Select
ActiveCell.FormulaR1C1 = "Week 1"
With Selection . . . This is used when one or more operations are performed
on a
End With selected range (or single cell). In the MakeSales macro, for
example, the following lines apply a 14-point font to the
selected cell:
With Selection.Font
.Name = "Arial"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Notice that in the above statement, all dialog box options are
listed, not just those that have been reset. With certain
shortcut methods, only a single option is listed, for example:
Selection.Font.Bold = True

©Copyright 2004 SVI Training Products, Inc. Page 17


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

All personal macros recorded during the current work session are stored in a single
module. You can switch from one module to another by selecting the module name
on the Window menu or by double-clicking on the module name in the Project
Explorer window. (To redisplay this window if it has been closed, choose the View,
Project Explorer command or click on the Project Explorer button on the
Standard toolbar.) You can copy code from one module to another by using the
standard Copy and Paste procedure. You can also delete a module, if necessary.

Project Explorer Button

©Copyright 2004 SVI Training Products, Inc. Page 18


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.6 Editing a Macro

You can edit a macro by modifying the current instructions, by inserting new
instructions and/or by deleting instructions.

In this exercise, you will edit your MakeSales macro. Specifically, you will have
the macro enter the title Monthly Sales (instead of Sales Data) in a 12-point font
(instead of a 14-point font). You will also have it enter the name of one additional
sales representative.

1. Make sure that the instructions of the MakeSales macro appear in the Microsoft Visual Basic
window.

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Change the text Sales Data (in the The text of the title is changed.
first instruction after the Sub
MakeSales ( ) statement and
comments at the beginning of the
macro) to Monthly Sales.

NOTE: Make sure that you do not


delete the quotation marks.
2. Change the line .Size = 14 (below The font size of the title is decreased.
the With Selection.Font instruction)
to
.Size = 12.

©Copyright 2004 SVI Training Products, Inc. Page 19


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


3. Revise the following instructions
as indicated below. The changes to
be made appear in bold type. (The
actual revisions, however, do not
need to be bolded.) Notice that the
fourth and fifth lines of the revised
instructions are new and must be
inserted into the macro.

NOTE: When you type the period


following the word "ActiveCell," a list
of associated entries will appear. You
can continue either by double-
clicking on the appropriate entry in
this list or by simply typing the entry.
Also, when you type the left
parenthesis following the word
"Range," a small window will appear
showing the syntax of the entry.

Current instructions:

Range("A8").Select
ActiveCell.FormulaR1C1 = "Bill Brown"
Range("A9").Select
ActiveCell.FormulaR1C1 = "Total"
Range("A9").Select
Selection.Font.Bold = True

Revised instructions:

Range("A8").Select
ActiveCell.FormulaR1C1 = "Bill Brown"
Range("A9").Select
ActiveCell.FormulaR1C1 = "Diana Dodd"
Range("A10").Select
ActiveCell.FormulaR1C1 = "Total"
Range("A10").Select
Selection.Font.Bold = True

©Copyright 2004 SVI Training Products, Inc. Page 20


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


4. Since the totals now appear in row
10 (and not in row 9) and six rows
are to be totaled (instead of five
rows), further changes need to be
made. Revise the following
instructions as indicated below.
(Again, the changes appear in bold
type.)

Current instructions:

Range("B9").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-5]C:R[-1]C)"
Range("B9").Select
Selection.AutoFill Destination:=Range("B9:E9"), Type:=xlFillDefault
Range("B9:E9").Select
Range("C1").Select
Selection.Font.Bold = True

Revised instructions:

Range("B10").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-6]C:R[-1]C)"
Range ("B10").Select
Selection.AutoFill Destination:=Range("B10:E10"), Type:=xlFillDefault
Range("B10:E10").Select
Range("C1").Select
Selection.Font.Bold = True

5. Click on the Save PERSONAL.XLS The workbook (including the changes you
button on the Standard toolbar. have made in the macro instructions) is
saved.

6. Choose the File, Close and Return The Visual Basic Editor is closed, and the
to Microsoft Excel command. Personal Macro Workbook is redisplayed.
7. Choose the Window, Hide The Personal Macro Workbook is once
command. again hidden.
8. Open a new workbook. You will now run the revised macro.

©Copyright 2004 SVI Training Products, Inc. Page 21


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


9. Make sure that cell A1 is selected. The macro is run. Notice the differences
Then press [CTRL] + [m]. in the operations that are performed.

NOTE: If a message box appears,


informing you of an error, click on either
the Debug or OK button (whichever
appears), make the necessary
correction(s) in the Microsoft Visual Basic
window, save the workbook, and then
return to Excel. (Click on the OK button
in the message box that subsequently
appears.) Close the current workbook,
without saving it, open a new workbook,
and then run the macro once again.
10. Close the workbook, without
saving it.

©Copyright 2004 SVI Training Products, Inc. Page 22


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

1. Unhide the Personal Macro Workbook.

2. Display the instructions of the MakeProfits macro in the Visual Basic Editor.

3. Revise the appropriate instructions so that the macro will:

a) Display the title in a different font size.

b) Enter the following item descriptions (in lieu of those it currently enters):

Model P
Model Q
Model R
Model S
Model T

c) Extend the model to six years. (This will necessitate changes in various
instructions, including those that add borders to the table.)

4. Save the changes.

5. Close the Visual Basic Editor, and return to Excel.

6. Hide the Personal Macro Workbook.

7. Open a new workbook.

8. Run the revised macro, and verify the changes you have made.

9. Close the workbook, without saving it.

©Copyright 2004 SVI Training Products, Inc. Page 23


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.7 Including Relative Cell References in a Macro

When you record a macro, cell references are normally recorded as absolute. Macro
execution, as a result, always affects the same area of a worksheet, regardless of
where the cell pointer is located prior to running a macro.

There may be times, however, when you will want a macro to perform operations
relative to the initial location of the cell pointer. This can be accomplished by
selecting the Relative Reference button on the Stop Recording toolbar before
recording an operation.

Relative Reference Button

In this exercise, you will record two macros -- one that includes relative cell
references and one that includes absolute cell references. You will then
compare the result of each macro when it is run.

1. Open a new workbook. Make sure that the cell pointer is located in cell A1.

You will begin by recording a macro that includes relative cell references.

©Copyright 2004 SVI Training Products, Inc. Page 24


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


1. Choose the Tools, Macro command, The Record Macro dialog box is
followed by Record New Macro. displayed.
2. Type: RelMacro1 The macro name is entered, and the
Make sure that Personal Macro Macro Recorder is turned on.
Workbook appears in the Store
macro in box. Then choose the OK
button.

NOTE: You can "choose" a button


either by clicking on it or by pressing
[ENTER].
3. Click on the Relative Reference The button is selected. Therefore, cell
button on the Stop Recording toolbar. references will be recorded as relative.
4. Press [DOWN ARROW]. Text is entered into cell A2.
Type: Test Data
Press [ENTER].
5. Click on the Stop Recording button. The Macro Recorder is turned off.

6. Delete the text in cell A2. Then You will now record a macro that includes
select cell A1. absolute cell references.
7. Choose the Tools, Macro command, The Record Macro dialog box is
followed by Record New Macro. redisplayed.
8. Type: AbsMacro1 The macro name is entered, and the
Choose the OK button. Macro Recorder is turned on. Notice that
the Relative Reference button is still
selected.
9. Click on the Relative Reference The button is deselected. Therefore, cell
button. references will once again be recorded as
absolute.
10. Press [DOWN ARROW]. Text is entered into cell A2.
Type: Test Data
Press [ENTER].
11. Click on the Stop Recording button. The Macro Recorder is turned off.
12. Delete the text in cell A2. Then You will now run the macro you have just
select cell D8. recorded.
13. Using the Tools, Macro, Macros The text "Test Data" is entered into cell
command, run the macro named A2.
AbsMacro1.
14. Select cell D8. You will now run the previous macro you
recorded.

©Copyright 2004 SVI Training Products, Inc. Page 25


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments


15. Using the Tools, Macro, Macros The text "Test Data" is entered into cell
command, run the macro named D9.
RelMacro1.
16. Unhide the Personal Macro
Workbook.
17. Using the Tools, Macro, Macros The macros of the Personal Macro
command, display the Macro dialog Workbook are displayed in the Microsoft
box. In the list of macros, click on Visual Basic window. The instructions of
RelMacro1. Then click on the Edit the RelMacro1 and AbsMacro1 macros
button. are illustrated on the following page.

NOTE: Absolute macros record actual


cell references (for example, Range
("A2").Select in AbsMacro1). This
ensures that whenever the macro is run,
the specified cell (A2 in AbsMacro1) will
be selected. Relative macros, on the
other hand, record cell references in
terms of offsets from the current location
of the cell pointer (for example,
ActiveCell.Offset(1,
0).Range("A1").Select in RelMacro1).
The arguments following Offset indicate
how the cell pointer is to be moved (one
cell down, zero cells to the right in
RelMacro1).

©Copyright 2004 SVI Training Products, Inc. Page 26


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

ACTION (You Do) COMPUTER RESPONSE / Comments

18. Click on the Close button on the Title The Visual Basic Editor is closed, and the
bar of the Microsoft Visual Basic Personal Macro Workbook is redisplayed.
window.
19. Hide the Personal Macro
Workbook.

©Copyright 2004 SVI Training Products, Inc. Page 27


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

1. Delete all text in the current worksheet.

2. Select cell A1. Record a macro, named RelMacro2 that enters the specified labels into the
following cells (recording the cell references as relative):

Cell B2: North


Cell C2: South
Cell A3: Income
Cell A4: Costs

3. Delete all text from the worksheet.

4. Select cell A1. Record another macro, named AbsMacro2, that enters the labels specified in step
2 into the same cells (recording the cell references this time as absolute).

5. Delete all text from the worksheet.

6. Run both macros with the cell pointer initially located each time in cell D10.

7. Close the workbook, without saving it.

©Copyright 2004 SVI Training Products, Inc. Page 28


Excel 2003 Macros Section 9 - Creating and Using Personal Macros

9.8 Summary

In this section, you have learned how to:

 Record a personal macro. Use the Tools, Macro, Record New


Macro command and the Personal
Macro Workbook option in the Record
Macro dialog box.

 Run a personal macro. Use the Tools, Macro, Macros


command (or the shortcut key
combination, if one
has been assigned).

 Unhide the Personal Macro Use the Window, Unhide command.


Workbook.

 Hide the Personal Macro Use the Window, Hide command.


Workbook.

 Edit a macro. Modify, insert and/or delete


instructions in the Visual Basic Editor.

 Open the Visual Basic Editor. Use the Tools, Macro, Macros
command and the Edit button
in the Macro dialog box.

 Include relative cell references in Use the Relative Reference button (on
a macro. the Stop Recording toolbar).

©Copyright 2004 SVI Training Products, Inc. Page 29


SECTION 10

INTRODUCTION

©Copyright 2004 SVI Training Products, Inc.


Excel 2003 Macros Section 10 - Introduction

10 INTRODUCTION
Welcome to this one-day Microsoft Office Excel 2003 Macros course. The primary
objective of the course is to broaden a user's knowledge of Microsoft Office Excel
2003, hereafter referred to as simply "Excel," in most cases. More detailed objectives
are listed later in this section.

10.1 Course Prerequisites

You will need the following to complete this course:

 A personal computer with a Pentium III, 233 MHz or higher microprocessor.

 A minimum of 128 MB of random access memory.

 Microsoft Windows 2000 with Service Pack 3 or later, or Microsoft Windows XP


or later operating system and Microsoft Office Excel 2003, properly installed.

 A Super VGA (800 X 600) or higher-resolution monitor with 256 colors.

 An installed pointing device (mouse) that is supported by Microsoft Windows 2000 or


later.

 An installed printer.

 A diskette containing the course data files.

 This training manual.


A basic knowledge of using a personal computer in the Microsoft Windows
environment is an essential prerequisite for this course.

Some experience in working with Excel is also required. In particular, you should be
able to:

 Start and exit from Excel.

 Open, save and close a workbook.

 Create and print a worksheet.

 Perform basic worksheet editing operations, such as copying and moving cell
entries, clearing cells, and inserting rows and columns.

 Performing basic worksheet formatting operations, such as adjusting column width


and row height, realigning cell entries, changing the font and number format of
cell entries, as well as adding a border and shading to a worksheet.

 Assign a name to a range.

©Copyright 2004 SVI Training Products, Inc. Page 1


Excel 2003 Macros Section 10 - Introduction

10.2 Course Objectives

After participating in this course, you should be able to:

 Record and run a personal macro.

 Record and run a workbook macro.

 Edit a macro.

 Add a macro button to a worksheet.

 Open a new module in the Visual Basic Editor.

 Display a data prompt during macro execution.

 Use a conditional statement in a macro.

 Use a control loop in a macro.

 Place a combo box on a worksheet.

 Place a check box on a worksheet.

 Link a control to worksheet data.

 Create a new toolbar.

 Add a button to a toolbar.

 Assign a macro to a toolbar button.

 Create a new menu.

 Add an item to a menu.

 Assign a macro to a menu item.

 Display Visual Basic Help information.

©Copyright 2004 SVI Training Products, Inc. Page 2


Excel 2003 Macros Section 10 - Introduction

10.3 Course Conventions

A number of conventions are used in this manual. Please be sure that you
understand them.

The course is divided into sections. Most sections consist of an introduction and
various subsections.

Most subsections include an overview of the topic to be presented and an


exercise headed by the word Objective. The exercise itself is often preceded by a
section headed PREPARATION, which includes one or more preliminary instructions.
Be sure to follow any directions under this heading.

Exercises are presented in two columns, with each step clearly numbered. Your
instructions are in the column headed ACTION (You Do); the second column headed
COMPUTER RESPONSE / Comments describes the program response and/or may
include other comments. Be sure to complete each step in the order shown.

Instructions of an exercise may be a combination of selecting a command (or


command sequence), typing information and/or pressing one or more keys. Typical
examples are given below:

Example 1

2. Choose the File command.

This means that you should select the File command on the Menu bar.

Example 2

4. Choose the File, Open command.

This means that you should first select the File command on the Menu bar and then
select the Open option on the File menu.

Example 3

When a shortcut button is available for a command sequence, that button is usually
indicated.

6. Click on the Print button.

This means that you should position the mouse pointer on the Print button and then
click the mouse button. (When clicking on any command, button or other screen
object, or when dragging a screen object, use the left mouse button unless otherwise
instructed.)

©Copyright 2004 SVI Training Products, Inc. Page 3


Excel 2003 Macros Section 10 - Introduction

Example 4

8. Type: Department Budget


Press [ENTER].

This means that you should type the words Department Budget and then press the
[ENTER] key. (In such instructions, special keys, such as [ENTER], [ESC] and [F1], can
be easily identified because they are always enclosed in square brackets.)

Example 5

When you are required to press two keys at the same time, the + sign is used.

10. Press [CTRL] + [O].

This means that you should press the [CTRL] key and, while holding it down, press
the letter O.

At several points throughout the course, Further Practice activities are provided.
These have been included to enable you to review techniques you have learned.
Again, follow the instructions carefully. If necessary, refer to any notes you may have
taken as you work through these activities.

This course assumes that you are using a mouse. Basic mouse techniques are
summarized below.

ACTION DESCRIPTION
Point Position the mouse pointer on the specified screen item.
Click Press and release the left mouse button.
Double-click Press and release the left mouse button two times in rapid
succession.
Right-click Press and release the right mouse button.
Drag Move the mouse pointer from its initial position to another area of
the screen while holding down the left mouse button.

©Copyright 2004 SVI Training Products, Inc. Page 4


Excel 2003 Macros Section 10 - Introduction

1. This course assumes that all default Excel settings are in effect when you start the program.

2. The course also assumes that the security level is set to Medium. (The security level can be reset,
if necessary, in the Security dialog box, which is displayed by choosing the Tools, Macro, Security
command.)

3. What appears on your screen may sometimes vary slightly from what is shown in this manual.

©Copyright 2004 SVI Training Products, Inc. Page 5

Das könnte Ihnen auch gefallen