Excel 2000:
Customizing Excel
and Using Macros
© 2002 ComputerPREP, Inc. All rights reserved.
Lesson 1:
Customizing Excel Workspaces
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Set options
• Customize toolbars
• Arrange and save workspaces
Setting Options
• Set options to change the default appearance and
behavior of Excel
• To set options:
– Display the Options dialog box
– Click on the card containing the settings you
want to change
– Change the desired options
Customizing the Display
of Menus and Toolbars
• By default:
– The Standard and Formatting toolbars share one
row
– Menus display only frequently used commands
• To specify how menus and toolbars display:
– Display the Options card of the Customize dialog
box
– Specify to display each toolbar on its own
– Specify to display full menus
– Click on “Reset my usage data” to restore the
default display
Creating Custom Toolbars
• Create a custom toolbar to contain command
buttons you use frequently that are in several
different toolbars
• To create a custom toolbar:
– Display the Toolbars card of the Customize
dialog box and click on the New button
– Specify a name for the custom toolbar
– Display the Commands card and drag the
command buttons you want to the custom
toolbar
Adding and Deleting
Toolbar Buttons
• You can add, delete and rearrange toolbar buttons
on any toolbar by dragging them while the
Customize dialog box is open
• If the Customize dialog box is closed:
– To move a button: press and hold ALT and drag
the button
– To copy a button: press and hold CTRL+ALT
and drag the button
– To delete a button: press and hold ALT and drag
the button into the worksheet area
Resetting and
Deleting Toolbars
• You can reset built-in toolbars, but not custom toolbars
• You can delete custom toolbars, but not built-in
toolbars
• To reset a built-in toolbar:
– Display the Toolbars card of the Customize dialog
box, click on the toolbar you want to reset, then
click on the Reset button
• To delete a custom toolbar:
– Display the Toolbars card of the Customize dialog
box, click on the toolbar you want to delete, then
click on the Delete button
Arranging and
Saving Workspaces
• Workspace file – a file that contains a group of
workbooks arranged for efficient access
• To create a workspace file:
– Open and arrange the workbooks that you want
to include in the workspace
– Display the Save Workspace dialog box and
specify a name for the workspace
Lesson 2:
Customizing Startup
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Open workbooks at startup
• Open custom workspaces at startup
• Create desktop icons
Opening Workbooks and
Custom Workspaces at
Startup
• Startup folder – a folder that contains files that will
open automatically every time you start Excel
• The Xlstart folder is the startup folder for Excel
• You can copy one or more workbooks to the
Xlstart folder
• If the Xlstart folder is empty, a blank workbook
displays when you start Excel
• You can also open a workspace file by saving the
workspace in the Xlstart folder
Creating Desktop Icons
• You can create desktop icons that start Excel and
open workbooks or workspaces automatically
• To create desktop icons:
– Create a shortcut that launches the application
using the Create Shortcut dialog box
– Display the Shortcut card of the Properties
dialog box
– Click at the end of the text string in the Target
text box
– Press SPACE, then type the name of the file you
want to open
Lesson 3:
Collaborating with Workgroups
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
•
•
•
•
Create templates
Edit templates
Create AutoTemplates
Collaborate with workgroups
Creating Templates
• Template – a workbook you use to create other
workbooks that will have the same formatting and
page layout
• When you create a template:
– Include the text, graphics, formatting, and
macros that will apply to all workbooks you
create based on the template
– Do not include data that will vary from
workbook to workbook
– Unlock data entry cells and apply worksheet
protection
Creating Templates
(cont’d)
• To create a template:
– Open (or create) the workbook from which you
will create the template
– Display the Save As dialog box
– Click on Template (*.xlt) in the Save as type
drop-down list
– Type a name for the template
– Click on the Save button
Creating Templates
(cont’d)
• To create a new workbook based on a template:
– Display the New dialog box
– Double-click on the name of the template on
which you want to base the new workbook
– Enter data in the data entry cells and save the
workbook with a new name
Editing Templates
• Edit templates just as you would edit any
worksheet you create in Excel
• To edit a template:
– Open the template that you want to edit
– Deactivate worksheet protection if necessary
– Make the desired changes
– Save the template
Creating AutoTemplates
• AutoTemplate – a template on which new
workbooks are based by default
• To create an AutoTemplate:
– Create a workbook with the formatting you want
– Save the workbook as a template named
“Book” in the Xlstart folder
• You must name the template “Book”; if you use
any other name, Excel will continue to use the
default workbook layout
Changing Workbook
Properties
• You can view and set workbook properties using the five
cards in the Properties dialog box:
– General card – displays the file type, name, location, and
other attributes
– Summary card – allows you to add specific information
about the workbook
– Statistics card – displays the creation date, the last time
the workbook was modified, the user who modified it, and
the number of revisions
– Contents card – displays worksheet names, charts,
reports and macro sheets
– Custom card – enables you to create your own custom
properties
Creating a Shared Workbook
• Shared workbook – a workbook that has been set
up to allow multiple users on a network to view
and edit the workbook simultaneously
• After you share a workbook, Excel automatically
keeps track of the changes by you and by other
users by maintaining a change history
– Change history – a log of all changes made to a
shared workbook during a specified time period
Viewing Tracked Changes
• When you share a workbook, Excel keeps track of
changes made by you or other users
• When you activate tracked changes, changed cells
are surrounded by blue boxes with a triangle in the
upper-left corner
• The column and row indicators for the changed
cells display in red
• When you position the mouse pointer over a
changed cell, a comment displays describing the
change
Accepting and
Rejecting Changes
• When tracked changes is active, you can choose
to accept or reject changes
• You can accept or reject each change individually
or
• You can accept all changes or reject all changes at
once
Merging Workbooks
• You can merge workbooks to join all changes together
• Before merging, workbooks must meet the following
requirements:
– Workbooks must be copies of the same workbook
– Each copy must have a different file name
– The workbooks must either not have passwords or
all have the same password
– The workbook from which the copies were originally
made must have been a shared workbook
– When copies were made, the change history must
have been turned on
Lesson 4:
Using AutoFormats in
Worksheets and Charts
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Use built-in AutoFormats
• Create custom chart formats
Applying AutoFormats to
Worksheets
• AutoFormat – a set of formatting commands such
as font size, patterns or alignment that you apply
to selected cells at one time
• To apply an AutoFormat to a worksheet:
– Display the AutoFormat dialog box
– Select an AutoFormat
– Click on Options to specify the type of
AutoFormat to apply: numbers, borders, fonts,
patterns, text and graphic alignment, column
widths and row heights
– Click on OK
Applying AutoFormats to
Charts
• To apply AutoFormats to charts:
– Display the Standard Types card of the Chart
Type dialog box
– Specify a chart type and chart sub-type
– Click on OK
Creating Custom Chart
Formats
• You can format a chart, save the format as a
custom chart type, then apply it to other charts
• You can create a new chart format or modify a
built-in chart format
• Modify chart formats using the Format dialog box
for various chart elements
• Save the custom chart format using the Custom
Types card of the Chart Type dialog box
Creating Custom Chart
Formats (cont’d)
• To apply a custom chart type:
– Display the Custom Types card of the Chart Type dialog
box
– Display the user-defined chart types
– Double-click on the custom chart type
• To delete a custom chart type:
– Display the Custom Types card of the Chart Type dialog
box
– Display the user-defined chart types
– Click on the custom chart type, then click on Delete
• You cannot restore a deleted custom chart type
Lesson 5:
Controlling Macros
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Control macro cell references
• Save macros for selective use
Reviewing Macros
• Macro – a series of commands that you record or write,
and that you can play back later to automate your work
• Visual Basic – a programming language used to write
programs and macros in Microsoft Office applications
• Module sheet – a worksheet that contains a macro or
macros
• Use the Record Macro dialog box to start macro
recording and display the Stop Recording toolbar
• Use the Macro dialog box to run, edit and delete
macros
Controlling Macro Cell
Reference
• The Stop Recording toolbar contains:
– The Stop button
– The Relative Reference button
• Use the Relative Reference button to toggle
between specifying a(n):
– Relative cell reference – allows the macro to
target varying cells, depending on the current
position of the cell pointer, or
– Absolute cell reference - ensures that the macro
will always process the same worksheet cells
(the default)
Saving Macros for Selective
Use
• You can save macros:
– In the current workbook (the default)
– In a new workbook
– In the Personal Macro Workbook
• Personal Macro Workbook – a workbook that
contains macros that are always available in every
workbook
Saving Macros for Selective
Use (cont’d)
• To save a macro in the Personal Macro Workbook:
– Display the Record Macro dialog box
– Display the “Store macro in” drop-down list
– Click on Personal Macro Workbook
– Continue to record and save the macro
• To save a macro in a new workbook:
– Display the Record Macro dialog box
– Display the “Store macro in” drop-down list
– Click on New Workbook
– Continue to record and save the macro
Lesson 6:
Editing Macros
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
•
•
•
•
•
Open the Visual Basic environment
Insert procedures
Find and replace code
Delete and copy code
Add comments
Opening the Visual Basic
Environment
• When you edit a macro, you open the Visual Basic
environment, which consists of three windows:
– The Project Explorer window – displays a
hierarchical list of worksheets and modules in
the workbook
– The Code window – displays the Visual Basic
code for the current macro
– The Immediate window – used to test the
results of commands you type
Opening the Visual Basic
Environment (cont’d)
• To open the Visual Basic environment:
– Display the Macro dialog box
– Select the macro you want to edit
– Click on the Edit button
Inserting Procedures
• Procedure – a group of statements and commands
that produces a result
• Procedures always begin with a Sub statement
and end with an End Sub statement
• To insert procedures:
– Type Visual Basic code in the Code window, or
– Record macro keystrokes, then copy and paste
the code into the Code window of an existing
macro
Finding and Replacing Code
• You can use the Edit Find and Edit Replace
features to find and replace code in a macro in the
same manner as you would text in a worksheet
• In the Visual Basic environment, the Find and
Replace dialog boxes contain options for
searching:
– Procedures
– Modules
– Projects
– Selected text
Deleting and Copying Code
• When you record a macro, code is generated for
every action you perform until you stop recording
• You delete and copy macro code in the Code
window in the same manner as you would edit text
Adding Comments
• Comments are text you can add within a macro
that are not part of the macro code
• To designate text as a comment, type an
apostrophe (‘) as the first character in the
comment line
• When you run the macro, all comments will be
ignored
Lesson 7:
Running Macros
from Menus and Buttons
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
•
•
•
•
Assign macros to the menu bar
Assign macros to toolbar buttons
Assign macros to worksheet buttons
Change assigned macros
Assigning Macros
to the Menu Bar
• To assign a macro to a menu bar command:
– Display the Commands card of the Customize
dialog box
– Select Macros and drag Custom Menu Item to
the menu bar
– Specify a name for the new menu item
– Assign a macro to the new menu item
• Click on the new menu bar command to run the
assigned macro
Assigning Macros
to Built-in Toolbar Buttons
• To assign a macro to a built-in toolbar button:
– Display the Commands card of the Customize
dialog box
– Right-click on the toolbar button, click on
Assign Macro, then double-click on the macro
you want to assign to the button
• Click on the toolbar button to run the assigned
macro
• The macro overrides the default function of the
button until you reset the toolbar
Assigning Macros
to Custom Toolbar Buttons
• To assign a macro to a custom toolbar button:
– Display the Commands card of the Customize
dialog box
– Click on Macros and drag Custom Button to a
toolbar
– Right click on the custom button, click on
Assign Macro, then double-click on a macro to
assign the macro to the button
• Click on the custom button to run the assigned
macro
Assigning Macros
to Worksheet Buttons
• Assign a macro to a worksheet button if you want the
macro to be available only in a specific worksheet
• To create a worksheet button:
– Display the Forms toolbar, click on the Button tool,
then draw a worksheet button
– Double-click on a macro to assign the macro to the
worksheet button
– Select the default button name and type a name for
the worksheet button
• Click on the worksheet button to run the assigned
macro
Changing Assigned Macros
• To change a macro assigned to a worksheet
button:
– Press and hold CTRL, click on the worksheet
button, then release CTRL to select the button
– Change the name of the button if desired
– Right-click on a button selection handle, click
on Assign Macro, then double-click on a macro
to assign the macro to the worksheet button
Lesson 8:
Making Macros Interactive
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Display dialog boxes in macros
• Display message boxes in macros
Displaying Dialog Boxes in
Macros
• You can design a macro to prompt the user for
data by displaying a dialog box as the macro
executes
• The data provided by the user determines how the
macro will proceed
• InputBox function – macro code that specifies to
display a dialog box that requests input from the
user and assigns the entered text to a variable in
the macro
Displaying Dialog Boxes in
Macros (cont’d)
• Syntax:
InputBox(prompt as string,[title],[default],[left],
[top],[helpfile],[helpcontextID],[type])
– prompt – the text that displays in the dialog box
– title – the dialog box title
– default – the data that displays in the dialog box
if the user does not respond
– left – the horizontal position of the dialog box
– top – the vertical position of the dialog box
Displaying Dialog Boxes in
Macros (cont’d)
– helpfile – the help file to use to provide contextsensitive help for the dialog box
– helpcontextid – the help context number
assigned by the help author
– type – specifies the data type, such as text (the
default), formula, number, logical value (true or
false), cell reference, error value or an array of
values
Displaying Message Boxes in
Macros
• You can design a macro to add message boxes
that provide information during macro execution
• MsgBox function – macro code that specifies to
display a message box during macro execution
• When the message box displays, the user must
click on a button, then the macro will continue
running based on the button the user has chosen
Displaying Message Boxes in
Macros (cont’d)
• Syntax:
MsgBox(prompt,[buttons],[title],[helpfile],[context])
– prompt – the text that displays in the message box
– buttons – specifies the type of buttons that will
display (OK, Cancel, Yes, No and so forth)
– title – the message box title
– helpfile – the help file to use to provide contextsensitive help for the message box
– context – the help context number assigned by the
help author
Lesson 9:
Using Break Mode
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Insert breakpoints
• Insert stop statements
About Break Mode
• Break mode – a debugging tool you can use to
stop the execution of a macro in order to view the
result at the moment the macro stops
• Debug window – a window that displays the values
of expressions and variables in a macro when the
macro encounters a break point or stop statement
• Break point – puts a macro in Break mode and
displays the Debug window
• Stop statement – a line of code that halts a macro
during execution and displays the Debug window
Inserting Breakpoints
• When you insert a breakpoint, you can examine the values of
variables, properties, functions and expressions as a macro
executes
• To insert a breakpoint:
– Open the Visual Basic environment
– Click on the line of code where you want to insert the
breakpoint
– Click on the Breakpoint button in the Debug toolbar, or
– Press F9, or
– Right-click on the line of code and click on Toggle,
Breakpoint
Inserting Breakpoints
(cont’d)
• You monitor what data a macro is using and the
value of variables by adding watch expressions
– Watch expression – a macro that is specified for
display in the Debug window when the macro
execution is in Break mode
• Use the Add Watch dialog box to add watch
expressions
• You can set as many watch expressions as you
want
Inserting Stop Statements
• Stop statements are similar to breakpoints but you
must enter and remove them manually
• A stop statement consists of the word “Stop”
• You add a stop statement between lines of macro
code at the point where you want the macro to
enter Break mode while it is executing
Lesson 10:
Stepping Through Macros
© 2002 ComputerPREP, Inc. All rights reserved.
Objectives
• Step over procedures
• Step into procedures
Stepping Through Macros
• Stepping – a process by which you can execute
macro code one statement at a time
• When you reach a previously set breakpoint or
stop statement, you can choose to step through
statements by stepping over them or stepping into
them
• Step over - a process by which you execute all the
statements within a procedure at once
• Step into - a process by which you execute all the
statements within a procedure one at a time
Stepping Through Macros
(cont’d)
• Use the step over feature to eliminate errors in the
overall structure of the macro and to broadly
determine in what procedure the error may lie
• Use the step into feature to help you exactly
pinpoint in what statement an error may lie