Upload
myron-leonard
View
226
Download
2
Tags:
Embed Size (px)
Citation preview
Microsoft Excel 2010® ®
Tutorial 8: Developing an Excel Application
XPXPXP
New Perspectives on Microsoft Excel 2010 2
Objectives• Create an application• Create, edit, and delete defined names for
cells and ranges• Paste a list of defined names as
documentation• Use defined names in formulas• Add defined names to existing formulas
XPXPXP
New Perspectives on Microsoft Excel 2010 3
Objectives• Create validation rules for data entry• Protect the contents of worksheets and
workbooks• Add, edit, and delete comments• Learn about macro viruses and Excel security
features• Add the Developer tab to the Ribbon
XPXPXP
New Perspectives on Microsoft Excel 2010 4
Objectives• Create and run a macro• Edit a macro using the Visual Basic Editor• Assign a macro to a keyboard shortcut and a
button• Save and open a workbook in macro-enabled
format• Minimize the Ribbon
XPXPXP
New Perspectives on Microsoft Excel 2010 5
Visual Overview
XPXPXP
New Perspectives on Microsoft Excel 2010 6
Excel Application and Defined Names
XPXPXP
New Perspectives on Microsoft Excel 2010 7
Planning an Excel Application• A spreadsheet written or tailored to meet
specific needs• The interface helps others use it• Typically includes reports and charts, a data
entry area, a custom interface, instructions, and documentation
XPXPXP
New Perspectives on Microsoft Excel 2010 8
Naming Cells and Ranges• Use a defined name to:–Assign a meaningful, descriptive name to a
cell or range–Quickly navigate within a workbook to the
cell with the defined name–Create a more descriptive formula
XPXPXP
New Perspectives on Microsoft Excel 2010 9
Creating Defined Names• Must begin with a letter or an underscore• Can include letters, numbers, periods and
underscores, but not other symbols or spaces• Cannot be a valid cell address, function name,
or reserved word• Can include as many as 255 characters– Short, meaningful names (5–15 characters)
are more practical• Are not case sensitive
XPXPXP
New Perspectives on Microsoft Excel 2010 10
Creating Defined Names• Use the Name box to create defined names
XPXPXP
New Perspectives on Microsoft Excel 2010 11
Creating Defined Names• Use the Selection dialog box to create defined
names by selection
XPXPXP
New Perspectives on Microsoft Excel 2010 12
Creating Defined Names• Use the Name Manager dialog box to edit and
delete defined names
XPXPXP
New Perspectives on Microsoft Excel 2010 13
Creating Defined Names• Use the Paste Names Command to generate a
list of names• Paste defined names in the Documentation
worksheet after the workbook is complete
XPXPXP
New Perspectives on Microsoft Excel 2010 14
Using Defined Names in Formulas• Descriptive formulas are simpler to enter and
understand– If a range reference is used rather than a
defined name, defined names do not automatically replace the range reference in the formula
XPXPXP
New Perspectives on Microsoft Excel 2010 15
Adding Defined Names to Existing Formulas• Defined names are not automatically
substituted for cell addresses in a formula• Replace cell addresses in existing formulas
with their defined names to make formulas more understandable
XPXPXP
New Perspectives on Microsoft Excel 2010 16
Visual Overview
XPXPXP
New Perspectives on Microsoft Excel 2010 17
Data Validation and Protection
XPXPXP
New Perspectives on Microsoft Excel 2010 18
Validating Data Entry• Ensures that correct data is entered and stored in a
worksheet– Protects cells with formulas from accidental
deletion– Reduces repetitious keystrokes and mouse clicks
• Each validation rule defines criteria for data that can be stored in a cell or range
• Use Data Validation dialog box to specify validation criteria, input message, and error alert for the active cell
XPXPXP
New Perspectives on Microsoft Excel 2010 19
Specifying Validation Criteria• When you create a validation rule, specify the
type of data allowed as well as a list or range of acceptable values (validation criteria)
XPXPXP
New Perspectives on Microsoft Excel 2010 20
Specifying Validation Criteria
XPXPXP
New Perspectives on Microsoft Excel 2010 21
Creating an Input Message• Reduces the chance of a data-entry error• Provides additional information about type of
data allowed for the cell• Appears as a ScreenTip next to selected cell
XPXPXP
New Perspectives on Microsoft Excel 2010 22
Creating an Error Alert Style and Message• An error alert determines what happens after
a user attempts to make an invalid entry in a cell that has a validation rule defined
• Tree error alert styles: Stop, Warning, and Information
XPXPXP
New Perspectives on Microsoft Excel 2010 23
Creating a List Validation Rule• Restricts a cell to accept only entries that are
on a list you create• Create the list of valid entries in the Data
Validation dialog box, or use a list of valid entries in a single column or row
XPXPXP
New Perspectives on Microsoft Excel 2010 24
Protecting a Worksheet and a Workbook• Reduces data-entry errors by limiting access to
certain parts of the workbook• Prevents users from changing cell contents,
workbook organization, or viewing formulas
XPXPXP
New Perspectives on Microsoft Excel 2010 25
Locking and Unlocking Cells• A cell’s locked property determines whether
changes can be made to that cell– Locked property has no impact as long as
worksheet is unprotected; after worksheet is protected, locked property is in control–Default: Locked property is turned on for
each cell, and worksheet protection is turned off
• Common practice: Protect the worksheet, but leave some cells unlocked
XPXPXP
New Perspectives on Microsoft Excel 2010 26
Protecting a Worksheet• Specify the actions still available to users
• A protected worksheet can be unprotected–Require a password to turn off protection
only if you are concerned that users might make changes
XPXPXP
New Perspectives on Microsoft Excel 2010 27
Protecting a Workbook• Keeps a worksheet from being modified–Protecting the structure prohibits renaming,
deleting, hiding, or inserting worksheets–Protecting the windows prohibits moving,
resizing, closing, or hiding parts of the window
• Default: Protect only the structure of the workbook, not the windows used to display it
XPXPXP
New Perspectives on Microsoft Excel 2010 28
Unprotecting a Worksheet and a Workbook• A worksheet must be unprotected to edit its
contents• A workbook must be unprotected to change
its structure
XPXPXP
New Perspectives on Microsoft Excel 2010 29
Inserting Comments• Use comments to:– Explain contents of a particular cell–Provide instructions to users– Share ideas and notes from several users
collaborating on a project
XPXPXP
New Perspectives on Microsoft Excel 2010 30
Visual Overview
XPXPXP
New Perspectives on Microsoft Excel 2010 31
Working with Macros
XPXPXP
New Perspectives on Microsoft Excel 2010 32
Automating Tasks with Macros• Macros perform repetitive tasks consistently
and faster than you can• After the macro is created and tested, tasks
are done exactly the same way each time• Use Developer tab to create and run macros
XPXPXP
New Perspectives on Microsoft Excel 2010 33
Protecting Against Macro Viruses• Virus–Computer program designed to copy itself
into other programs with the intention of causing mischief or harm
• Macro viruses– Type of virus that uses a program’s own
macro programming language to distribute the virus
• Microsoft Office 2010 provides several options for levels of security
XPXPXP
New Perspectives on Microsoft Excel 2010 34
Macro Security Settings• Control what Excel will do about macros when
the workbook is opened
XPXPXP
New Perspectives on Microsoft Excel 2010 35
Macro Security Settings• Set macro security in the Trust Center
• Use Trusted Locations to define file paths for files considered trustworthy
• Use a digital signature to identify the author of a workbook that contains macros
XPXPXP
New Perspectives on Microsoft Excel 2010 36
Recording a Macro• For simple macros, use the macro recorder to
record keystrokes and mouse actions as they are performed
• For sophisticated macros, enter a series of commands in the Visual Basic for Applications (VBA) programming language
XPXPXP
New Perspectives on Microsoft Excel 2010 37
Running a Macro• Either use the specified shortcut key or select
the macro in the Macro dialog box
XPXPXP
New Perspectives on Microsoft Excel 2010 38
Options for Fixing Macro Errors• Rerecord the macro using the same macro
name• Delete the recorded macro; record it again• Run the macro one step at a time to locate the
problem; use one of the previous methods to correct the problem
XPXPXP
New Perspectives on Microsoft Excel 2010 39
Working with the Visual Basic Editor
• Components–Code window contains the VBA code–Project Explorer window displays a treelike
diagram consisting of every open workbook–Menu bar contains menus of commands
used to edit, debug, and run VBA statements
• Accessed through Macro dialog box or Visual Basic button in Code group on Developer tab
XPXPXP
New Perspectives on Microsoft Excel 2010 40
Working with the Visual Basic Editor
XPXPXP
New Perspectives on Microsoft Excel 2010 41
Understanding the Structure of Macros• Each macro (sub procedure) begins with Sub
followed by the name of the sub procedure and a set of parentheses (the arguments)
• Comments about the macro follow the statement and do not include any actions
• The body of the macro follows the comments• End Sub statement indicates the end of the
sub procedure
XPXPXP
New Perspectives on Microsoft Excel 2010 42
Understanding the Structure of Macros• A Code window can contain several sub
procedures• Each procedure is separated from the others
by SubProcedureName() statement at the beginning, and End Sub statement at the end
• Sub procedures are organized into modules
XPXPXP
New Perspectives on Microsoft Excel 2010 43
Editing a Macro Using the Visual Basic Editor• The Visual Basic Editor provides tools to assist
in writing error-free code• As you type a command, the editor provides
pop-up windows and text to help you insert the correct code
XPXPXP
New Perspectives on Microsoft Excel 2010 44
Creating Macro Buttons• A macro can be assigned to a button placed
directly in the worksheet• Clicking a button (with a descriptive label) can
be more intuitive and simpler than trying to remember combinations of keystrokes
• Form Controls
XPXPXP
New Perspectives on Microsoft Excel 2010 45
Creating Macro Buttons
XPXPXP
New Perspectives on Microsoft Excel 2010 46
Saving Workbooks with Macros• Default Excel Workbook format is a macro-free
workbook (.xlsx file extension)• To save the workbook with the macros, save
the file as a macro-enabled workbook (.xlsm file extension)
XPXPXP
New Perspectives on Microsoft Excel 2010 47
Opening a Workbook with Macros• First time a workbook opens, a Security
Warning appears in Message Bar providing the option to:– Enable macros so they can be run, or –Open the workbook with the macros
disabled
XPXPXP
New Perspectives on Microsoft Excel 2010 48
Customizing the Ribbon• Minimize the Ribbon–Makes more space for a worksheet–Only Quick Access Toolbar and tab names
display
• Create new tabs and groups• Hide tabs or commands • Rename tabs or commands