Tải bản đầy đủ (.pdf) (99 trang)

excel 2002 power programming with vba phần 2 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (872.85 KB, 99 trang )

4799-2 ch03.F 6/11/01 1:14 PM Page 60
Understanding
Excel’s Files
I
f you plan to do any advanced work with Excel, it’s critical
that you become familiar with the various ways to start
Excel, and understand what happens when the application is
launched. It’s also a good idea to have an understanding of
the various files used and generated by Excel. These topics
are covered in this chapter.
Starting Excel
Excel can be started various ways (depending on how it’s
installed). All methods ultimately execute the Excel.exe exe-
cutable file.
When Excel starts, it reads its settings from the Windows
Registry and opens any add-ins that are installed (that is,
those that are checked in the Add-Ins dialog box). It then dis-
plays an empty workbook; the number of sheets in the work-
book is determined by a user-defined setting that is stored in
the Windows Registry. You can change this number by editing
the Sheets in the New Workbook setting located in the General
tab of the Options dialog box (select Tools➪ Options).
If your Xlstart folder contains any workbooks, they are
opened automatically — and a blank workbook does not
appear. If your Xlstart folder includes a workspace file, multi-
ple workbooks are opened in a customized workspace. You
can also define an alternate startup directory to hold other
worksheet or workspace files you want opened automatically.
You can set up this alternate startup directory by specifying a
path in the At startup, open all files in setting located in the
General tab of the Options dialog box. In previous versions of


Excel, this field was labeled Alternate startup file location.
4
4
CHAPTER
✦✦✦✦
In This Chapter
A description of the
various ways to start
Excel
A discussion of the
files used and
produced by Excel —
including the new
HTML file format
Details about how
Excel uses the
Windows Registry
✦✦✦✦
4799-2 ch04.F 6/11/01 9:28 AM Page 61
62
Part I ✦ Some Essential Background
If you want to change the default formats (or content) of blank workbooks that
you create, create a default workbook and save it as a template with the name
Book.xlt in your Xlstart folder. For details on creating and using template files, refer
to the online help.
Excel recognizes several command line switches. These are listed in Table 4-1.
Table 4-1
Excel Command Line Switches
Switch What It Does
/automation Forces Excel to start without loading add-ins and templates or processing

files in the Xlstart directory or the alternate startup file location. Use this
switch to perform a “clean-boot” of Excel.
/e Forces Excel to start in “embedded” mode. Use this switch when you
want to start Excel without creating a new workbook and without
displaying its splash screen.
/embedded Starts an invisible instance of Excel (not recommended).
/m Forces Excel to create a new workbook that contains a single Microsoft
Excel 4.0 macro sheet (obsolete).
/o Causes Excel to register itself in the Windows Registry. It replaces missing
Registry entries; it does not correct invalid entries (see /regserver, later in
this table).
/p directory Sets the active path to a directory other than the default directory.
/r filename Forces Excel to open the specified file in read-only mode.
/s Forces Excel to start in “safe” mode, and does not load any add-ins or
files in the Xlstart or alternate startup file directories.
/regserver Forces Excel to reregister itself in the Windows Registry and then quit. Use
this switch when you want Excel to rewrite all its Registry keys and
reassociate itself with Excel files, such as workbooks and charts.
/unregserver Forces Excel to unregister itself in the Windows Registry and then quit.
One way to specify any of these switches is to edit the properties of the shortcut
that starts Excel. For example, if you want Excel to use a folder named Xlfiles as its
default folder, you can use the /p switch and specify this in the Target field in the
Properties dialog box for the Excel shortcut. To access the Properties dialog box,
right-click the shortcut icon and click the Shortcut tab. For example, you can
change the Target to:
“C:\Program Files\Microsoft Office\Office\EXCEL.EXE” /p
C:\Xlfiles
Tip
4799-2 ch04.F 6/11/01 9:28 AM Page 62
63

Chapter 4 ✦ Understanding Excel’s Files
You can run multiple instances of Excel on a single system. Each instance is treated
as a separate task. And, most people have pretty good success running multiple
versions of Excel on a single system. For best results, install the versions in the
order of their release dates.
Excel’s File Extensions
As Excel goes about its business, it uses many files in addition to the Excel.exe exe-
cutable. These other files are loaded into memory as needed. Table 4-2 presents a
summary of the file types that Excel may write to your hard disk during installation,
or files that you may encounter when working with Excel.
Table 4-2
File Types Installed by Excel
File Type Description
CHM A compiled HTML help file.
DLL A Dynamic Link Library file. DLLs are used by Windows applications to store
program code.
EXE An executable file. Excel.exe is the executable file that runs Excel.
OLB An object type library file.
TXT A plain ASCII text file, readable from any text editor (such as NotePad). These
files often contain late-breaking information not found in the manuals.
XLA An Excel add-in file. Several are supplied with Excel, and you can also download
other add-ins or create your own.
XLB An Excel toolbar configuration file. The current toolbar configuration is stored in
the Windows directory in a file named Excel10.xlb (the filename is different in a
network environment).
XLC An Excel 4 chart file (obsolete beginning with Excel 5).
XLL An Excel link library file. For example, the Analysis ToolPak add-in uses this type
of file.
XLM An Excel 4 macro file (obsolete beginning with Excel 5).
XLS An Excel workbook file. Unfortunately, there is no way to tell from the extension

which version of Excel produced the file.
Continued
Note
4799-2 ch04.F 6/11/01 9:28 AM Page 63
64
Part I ✦ Some Essential Background
Table 4-2 (continued)
File Type Description
XLT An Excel template file.
XLW A workspace file that contains information about the windows and positions in
a workspace. This extension was also used for Excel 4 workbook files (obsolete
beginning with Excel 5 because all files are workbooks).
XLK A backup file.
Excel versions prior to Excel 2000 used standard Windows Help files (*.hlp). Excel
2000 and later use HTML Help. This system uses compiled HTML files with a *.chm
extension.
Spreadsheet File Formats Supported
Although Excel’s default file format is an XLS workbook file, it can also open and
save a wide variety of files generated by several other applications.
An important consideration is whether a particular file type can survive a “round
trip.” In other words, do you lose any information if you save a file in a particular
format and then reopen it in the same application? As you might expect, using
Excel’s native file format (XLS files) ensures that you’ll lose absolutely nothing—
as long as you use the latest version of XLS.
If you save and retrieve a file using a format other than the current XLS format, you
run the risk of losing some types of information — typically formatting and macros,
but sometimes formulas and charts.
In the sections that follow, I discuss the various types of files you can and cannot
use with Excel.
Lotus 1-2-3 spreadsheet files

Lotus spreadsheets come in several flavors:
✦ WKS files are single-sheet files used by 1-2-3 Release 1.x for DOS. Excel can
read and write these files.
Excel can also open Microsoft Works files, which also have a WKS extension.
Note
Caution
New
Feature
4799-2 ch04.F 6/11/01 9:28 AM Page 64
65
Chapter 4 ✦ Understanding Excel’s Files
✦ WK1 files are single-sheet files used by 1-2-3 Release 2.x for DOS. The format-
ting for these files is stored in *.all files (produced by the Allways add-in) or
FM1 files (produced by the WYSIWYG add-in). Excel can read and write all
these files. When you save a file to the *.wk1 format, you can choose which (if
any) type of formatting file to generate.
✦ WK3 files are generated by 1-2-3 Release 3.x for DOS, 1-2-3 Release 4.x for DOS,
and 1-2-3 Release 1.x for Windows. These files may contain more than one
sheet. The formatting for these files is stored in *.fm3 files (produced by the
WYSIWYG add-in). Excel can read and write WK3 files with or without the
accompanying FM3 file.
✦ WK4 files are generated by 1-2-3 Release 4.x for Windows and 1-2-3 Release 5.x
for Windows (Lotus finally got its act together and eliminated the separate for-
matting file). These files may contain more than one sheet. Excel can neither
read nor write these files. If you need to read a WK4 file into Excel, your only
option is to use 1-2-3 Release 4 for Windows (or later) and save the file in WK3
format, which Excel can read.
✦ 123 files are generated by 1-2-3 97 and 1-2-3 Millenium Edition. These files may
contain more than one sheet. Excel can neither read nor write these files. If
you need to read a 123 file into Excel, your only option is to use 1-2-3 and save

the file in WK3 format, which Excel can read.
Quattro Pro spreadsheet files
Quattro Pro files also exist in several versions:
✦ WQ1 files are the single-sheet files generated by Quattro Pro for DOS Versions 1,
2, 3, and 4. Excel can read and write these files.
✦ WQ2 files are generated by Quattro Pro for DOS Version 5. Excel can neither
read nor write this file format.
✦ WB1 files are generated by Quattro Pro for Windows Versions 1 and 5 (there are
no Versions 2 through 4). Excel can read, but not write, this file format.
✦ WB2 files are generated by Quattro Pro for Windows Version 6. Excel can neither
read nor write this file format.
✦ WB3 files are generated by Quattro Pro for Windows Versions 7 and 8. Excel can
neither read nor write this file format.
You can download a Quattro Pro file converter from Microsoft’s Web site. This con-
verter enables you to import Quattro Pro 97’s WB3 files. The URL for download is
/>quatt97.htm
Note
4799-2 ch04.F 6/11/01 9:28 AM Page 65
66
Part I ✦ Some Essential Background
Database file formats
DBF files are single-table database files generated by dBASE and several other
database programs. Excel can read and write DBF files up to and including dBASE 4.
Excel cannot read or write any other database file formats directly. You can, how-
ever, use Microsoft Query to access many other database file formats and then
copy or link the data into an Excel worksheet. You can run Microsoft Query directly
from Excel by using the Data➪ Get External Data ➪ New Database Query command.
Text file formats
Text files simply contain data with no formatting. There are several relatively stan-
dard text file formats, but there are no standard file extensions.

✦ Each line in tab-delimited files consists of fields separated by tabs. Excel can
read these files, converting each line to a row and each field to a column.
Excel also can write these files, using TXT as the default extension.
✦ Each line in comma-separated files consists of fields usually separated by
commas (countries that use a comma as a decimal symbol will use semi-
colons in CSV files). Sometimes text appears in quotes. Excel can read these
files, converting each line to a row and each field to a column. Excel can also
write these files, using CSV as the default extension.
✦ Each line in space-delimited files consists of fields separated by spaces. Excel
can read these files, converting each line to a row and each field to a column.
Excel also can write these files, using PRN as the default extension.
When you attempt to load a text file into Excel, the Text Import Wizard may kick in
to help you specify how you want the file retrieved.
To bypass the Text Import Wizard, press Shift when you click OK in the Open
dialog box.
You can also perform queries using text files. Use the Data ➪ Get External Data ➪
Import Text File command.
Other file formats
Other formats supported are the following:
✦ DIF (Data Interchange Format) file format was used by VisiCalc. I haven’t seen
a DIF file in ages. Excel can read and write these files.
✦ SYLK (SYmbolic LinK) file format was used by MultiPlan. SYLK files, too, are
quite rare these days. Excel can read and write these files.
Note
Tip
4799-2 ch04.F 6/11/01 9:28 AM Page 66
67
Chapter 4 ✦ Understanding Excel’s Files
Files Written by Excel
Excel can write several types of files, which I discuss in this section.

XLS files
The XLS workbook files produced by Excel 2002 use the same file format as Excel
2000 and Excel 97. These files cannot be opened by any version of Excel prior to
Excel 97. You can, however, save a workbook using any of the older Excel file for-
mats. You may lose some information that is specific to the later file format.
An Excel workbook or add-in file can have any extension you like. In other words,
these files need not be stored using an XLS or XLA extension.
Note
Which Version Created That XLS File?
Unfortunately, there is no direct way to determine which version of Excel created a particu-
lar XLS file. If you have an earlier version of Excel and attempt to open an XLS file that was
created in a later version, you’ll probably get an error message or a screenful of garbage
characters. But if you can open the file successfully, you can use a simple VBA statement to
determine the Excel version of the file.
Open the workbook, and make sure it’s the active workbook. Press Alt+F11 to activate the
Visual Basic Editor, and then press Ctrl+G to activate the Immediate window. Type the fol-
lowing statement, and press Enter:
Print ActiveWorkbook.FileFormat
The Immediate window displays a value that corresponds to the version of the active work-
book. This value is one of those shown in the following table:
Value Excel Version
16 Excel 2
29 Excel 3
33 Excel 4
39 Excel 5, 95
-4143 Excel 97, 2000, 2002
4799-2 ch04.F 6/11/01 9:28 AM Page 67
68
Part I ✦ Some Essential Background
Workspace files

A workspace file is a special file that contains information about an Excel workspace.
For example, if you have a project that uses two workbooks and you like to have
the workbook windows arranged in a particular way, you can save an XLW file (use
the File ➪ Save Workspace command) to save this window configuration. Then,
whenever you open the XLW file, Excel restores the desired workspace.
It’s important to understand that a workspace file does not include the work-
books — only the configuration information that makes those workbooks visible in
your Excel workspace. So if you need to distribute a workspace to someone else,
make sure that you include the workbook files as well as the XLW file. In addition,
the File ➪ Save Workspace command does not save the workbooks themselves.
Template files
You can save any workbook as a template file (XLT extension). Doing so is useful if
you tend to create similar files on a regular basis. For example, you may need to
generate a monthly sales report. You can save some time by creating a template
that holds the necessary formulas and charts for your report. When you start new
files based on the template, you need only plug in the values.
To create a new workbook that’s based on an existing template, use the File ➪ New
command, and select the template from the New dialog box.
Excel 2002 requires an extra step, because the preceding commands display the
New Workbook toolbar. From the toolbar, you can choose a source for the tem-
plate, including templates that you can download from Microsoft’s Web site.
Clicking the New toolbar button or pressing Ctrl+N does not enable you to select
a template. Rather, a default workbook is created.
If you create a template named Book.xlt, that template will be used as the basis for
new workbooks. In addition, you can create a template named Sheet.xlt, which is
used as the basis for new worksheets that you add to a workbook. Note that it is
not possible to create a template for chart sheets because Excel handles chart
templates differently.
Templates can be stored in two locations on your local computer:
✦ Your Xlstart folder. This is where you store autotemplates named Book.xlt and

Sheet.xlt. You can also put workbook templates in this folder.
✦ Your Templates folder. Workbook templates stored here appear in the New
dialog box.
Note
New
Feature
Caution
4799-2 ch04.F 6/11/01 9:28 AM Page 68
69
Chapter 4 ✦ Understanding Excel’s Files
The location of the Templates folder varies, depending on the version of Excel. To
find the location of your Templates folder, execute the following VBA statement:
MsgBox Application.TemplatesPath
Toolbar files
Excel stores toolbar and menu bar configurations in an XLB file. When you exit
Excel 2002, the current toolbar configuration is saved in a file named Excel10.xlb.
The exact location and name of this file varies with the version of Excel, so search
your hard drive for *.xlb and you’ll find it. This file contains information regarding
the position and visibility of all custom toolbars and custom menu bars, plus modi-
fications that you’ve made to built-in toolbars or menu bars.
Excel 2002’s online help lists the various names and locations of the XLB files for
various versions of Excel. Do a search for “xlb” to find this information.
Add-in files
An add-in is essentially a workbook file with a few important differences:
✦ The workbook’s
IsAddin property is True — which means that it can be
loaded using the Tools➪ Add-Ins command.
✦ The workbook is hidden and cannot be unhidden by the user. Consequently,
an add-in is never the active workbook.
✦ The workbook is not part of the

Workbooks collection.
Many add-ins provide new features or functions to Excel. You can access these new
features as if they were built into the product.
You can create your own add-ins from XLS workbook files. In fact, creating add-ins
is the preferred method of distributing some types of Excel applications. Add-ins
have an XLA extension by default, but you can use any extension you like.
Besides XLA add-ins, Excel supports XLL add-ins and (beginning with Excel 2000)
COM add-ins. These types of add-ins are created using software other than Excel.
This book discusses only XLA add-ins.
Chapter 21 covers the topic of add-ins in detail.
Cross-
Reference
Note
Tip
4799-2 ch04.F 6/11/01 9:28 AM Page 69
70
Part I ✦ Some Essential Background
Excel and HTML
HTML is the language of the World Wide Web. When you browse the Web, the docu-
ments that are retrieved and displayed by your browser are usually in HTML for-
mat. An HTML file consists of text information plus special tags that describe how
the text is to be formatted. The browser interprets the tags, applies formatting, and
displays the information.
Excel 2000 and later can use HTML as a native file format. In other words, you can
save a workbook in HTML format and then reopen the HTML file, and it will look
exactly as it did before you first saved it. All the Excel-specific information (such as
macros, charts, pivot tables, and worksheet settings) remains intact. HTML is a rel-
atively simple file format. The fact that an Excel workbook can survive the “round
trip” is just short of amazing.
Using HTML as a native file format may be amazing, but I think Microsoft may have

overemphasized the importance of this feature. In real life, this simply isn’t very
useful except in a small number of situations.
So how does it work?
The best way to understand how Excel can use HTML as a native file format is to
perform some simple experiments. Start with a new workbook, and make sure it has
only one worksheet. Enter a few values and a formula, do some simple formatting,
and then save the workbook in HTML format. Use the File ➪ Save As Web Page com-
mand, and make sure you select the Entire Workbook option. Figure 4-1 shows a
very simple workbook consisting of two values and a formula, with the formula cell
formatted bold. This is a good candidate for learning about the HTML files saved by
Excel.
Figure 4-1: Try saving a simple
workbook like this in HTML format.
The remainder of the material in this section assumes that you’re familiar with
HTML.
Note
4799-2 ch04.F 6/11/01 9:28 AM Page 70
71
Chapter 4 ✦ Understanding Excel’s Files
Next, open the HTML file in your browser. It will, of course, look pretty much like
the original workbook. However, it is a “dead” non-interactive document. Use the
browser’s View ➪ Source command to view the HTML code. You might be surprised
by what you see. Even HTML gurus might be overwhelmed by the complexity of
this “simple” Web document.
Following are a few observations about the HTML file:
✦ The entire Excel workbook can be represented by a single HTML file. In other
words, all the information needed to create an exact replica of the original
workbook is contained in the HTML file. This isn’t always the case, however.
Keep reading to find out when a simple HTML file no longer suffices.
✦ Most of the document is contained within the

<head> and </head> tags.
✦ A large portion consists of style definitions. This is the information between
the
<style> and </style> tags— which is embedded between the <head>
and </head> tags.
✦ The actual text that’s displayed in the browser is contained in a table
(between the
<table> and </table> tags).
✦ The formula is preserved by using a proprietary argument for the
<td> tag.
The proprietary argument is ignored by browsers, but Excel uses this informa-
tion when the file is reopened.
The HTML file produced for the simple workbook is more than 4,000 bytes in size,
which is quite large considering the simplicity of the displayed page. The extra
information, of course, is what Excel uses to create a workbook when the HTML file
is reopened.
Adding some complexity
The example workbook used in the preceding section is about as simple as it gets.
Now let’s add a small bit of complexity to the workbook and see what happens to
the HTML file.
Using the simple example file, select A1:A3 and press F11 to create a new chart
sheet. Save the file again and load it in your browser. You’ll find that it closely
resembles the Excel workbook, even down to the sheet tabs and navigation arrows
at the bottom!
The HTML file has more than doubled in size (it’s now up to about 10,000 bytes).
More importantly, you’ll find that the directory in which you saved the file has a
new subdirectory that contains additional files (six extra files using my simple
workbook). The files in this directory are necessary to display a replica of the work-
book in a browser and to re-create the workbook when the HTML file is reopened in
Excel.

4799-2 ch04.F 6/11/01 9:28 AM Page 71
72
Part I ✦ Some Essential Background
If you examine the HTML file, you’ll see that it’s much more complicated than the
original one and contains quite a bit of complex JavaScript code (JavaScript is a
scripting language supported by Internet Explorer and Netscape Navigator). At this
point, the HTML file has gotten well beyond the grasp of your average HTML author.
And that’s not even taking into account the other files dumped into the subdirectory.
The files are:
✦ Three HTML files (one for each sheet, plus a file that displays the tab strip).
✦ A GIF file (the chart).
✦ A CSS file (a cascading style sheet that holds formatting and display
information).
✦ An XML file. This is an “eXtensible Markup Language” file. XML is well beyond
the scope of this book. (Hey, I told you this stuff was getting complicated!)
You might want to open some other Excel workbooks and save them as HTML files.
You’ll soon discover another type of file that’s created in the subdirectory, an MSO
(for Microsoft Office) file. This is a binary file that holds the information necessary
to re-create Excel-specific features such as macros, pivot tables, conditional format-
ting, and so on.
As you may have surmised by now, saving an Excel workbook in HTML format
introduces lots of potential problems. For example, if you need to transfer your file
to another location, it’s imperative that you include all the supporting files as well.
If any of the supporting files are damaged, Excel cannot re-create the workbook.
And opening and saving HTML files is much slower than opening and saving
normal XLS files. To make a long story short, don’t save your workbooks in HTML
format unless you have a very good reason to do so.
What about interactivity?
If you’re still with me at this point, it’s time to introduce yet another level of com-
plexity. Excel can save HTML files that include spreadsheet interactivity. In other

words, when the HTML file is displayed in a browser, the user can actually interact
with the document as a spreadsheet— enter data, change formulas, adjust cell for-
matting, see “live” charts, and even drag data around in pivot tables. This feature,
which is called publishing (as opposed to saving), is limited in that you can only
save one sheet (not an entire workbook).
To get a feel for how this works, activate a sheet that contains formulas. Use the
File ➪ Save As Web Page command. In the Save As dialog box, choose the Selection:
Sheet option, and place a check mark next to Add interactivity. Click the Publish
button. You’ll get another dialog box (Publish as Web Page). Accept the defaults,
and click Publish.
When you open the HTML file in your browser, you’ll find that it displays a spread-
sheet-like object that is, in fact, interactive. Figure 4-2 shows an example, using
Microsoft’s Internet Explorer browser.
Caution
4799-2 ch04.F 6/11/01 9:28 AM Page 72
73
Chapter 4 ✦ Understanding Excel’s Files
You might expect that the HTML file generated for an interactive worksheet would
be much more complex than the example in the previous section. You’d be wrong.
Such a worksheet occupies a single HTML file. Since only one sheet is involved
when you publish, there’s no need to get involved with the tab strip stuff. The com-
plexity is handled by an ActiveX control. Because of this, the end user must have
Office 2000 or later installed (or have a license for the Microsoft Web Components
ActiveX control) to view an interactive Excel file in his or her browser.
This section was intended to provide a brief overview of the HTML feature in Excel
2000 and 2002. This topic is definitely fodder for a complete book— one that I
don’t choose to write, thank you.
Figure 4-2: An example of an interactive Excel worksheet
displayed in a browser
Note

What about the Script Editor?
You’ll find that this book ignores a complete aspect of Excel: the Microsoft Script Editor,
which you access by pressing Alt+Shift+F11. The Script Editor is used to edit the JavaScript
(or VBScript) code in an HTML document. I consider this topic to be beyond the scope of
this book, and useful to only a very small number of readers. In fact, I have never been in
contact with anyone who had any interest at all in this topic. Consequently, I focus on the
real meat of Excel: non-Web-based application development using VBA.
4799-2 ch04.F 6/11/01 9:28 AM Page 73
74
Part I ✦ Some Essential Background
Excel Settings in the Registry
In this section, I provide some background information about the Windows Registry
and discuss how Excel uses the Registry to store its settings.
About the Registry
Windows 3.1 used a Registration Database to store information about file associa-
tion and OLE registration. The Windows 95 (or later) Registry extends this concept
by storing configuration information for all types of applications, as well as
computer-specific information.
The Registry is essentially a hierarchical database that can be accessed by applica-
tion software. This information is stored in two data files: System.dat (for system-
specific information) and User.dat (for user-specific information). Both of these files
are located in the Windows folder. In addition, the Registry may use a file named
Policy.pol — a file that contains system policies that override the information in the
other files.
You can use the Registry Editor program (Regedit.exe, in the Windows folder) to
browse the Registry — and even edit its contents if you know what you’re doing.
Before beginning your explorations, take a minute to read the sidebar titled “Before
You Edit the Registry . . . “ Figure 4-3 shows what the Registry Editor looks like.
Figure 4-3: The Registry Editor lets you browse and make changes to the Registry.
4799-2 ch04.F 6/11/01 9:28 AM Page 74

75
Chapter 4 ✦ Understanding Excel’s Files
As I mentioned, the Registry is hierarchical. It consists of keys and values. Table 4-3
lists the top-level root keys of the Registry along with a brief description of the type
of information stored there.
Table 4-3
Top-Level Keys in the Windows Registry
Key Description
HKEY_CLASSES_ROOT Information on OLE, shortcut, and other interface features
HKEY_CURRENT_USER Data from the current user’s User.dat file (a duplicate of data
found in HKEY_USERS)
HKEY_LOCAL_MACHINE System-specific information from the System.dat file
HKEY_USERS Information about all users on the system
HKEY_CURRENT_CONFIG Hardware information
HKEY_DYN_DATA Information on installed devices
Excel’s settings
Information used by Excel 2002 is stored in
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Excel
In this section of the Registry, you’ll find a number of keys that contain specific
values that determine how Excel operates.
Before You Edit the Registry . . .
You can use the Regedit.exe program to change anything in the Registry, including informa-
tion that is critical to your system’s operation. In other words, if you change the wrong piece
of information, Windows may no longer work properly.
Therefore, it’s a good idea to take some simple precautions. First, make sure that you have
a startup diskette (you can do this by using the Add/Remove Programs app in the Control
Panel). You can use this diskette to start Windows in an emergency.
Second, get into the habit of using the Registry ➪ Export Registry File command in Regedit.
This command enables you to save an ASCII version of the Registry or just a specific branch
of the Registry. If you find that you messed up something, you can always import the ASCII

file to restore the Registry to its previous condition (use the Registry ➪ Import Registry File
command). Refer to the help file for Regedit for details.
4799-2 ch04.F 6/11/01 9:28 AM Page 75
76
Part I ✦ Some Essential Background
The Registry settings are updated automatically by Excel when Excel closes.
It’s important to understand that Excel reads the Windows Registry only once —
when it starts up. In addition, Excel updates the Registry settings only when Excel
closes normally. If Excel crashes your system (unfortunately, not an uncommon
occurrence), the Registry information is not updated. For example, if you change
one of Excel’s settings, such as the visibility of the status bar, this setting is not writ-
ten to the Registry until Excel closes by normal means.
Table 4-4 lists the Registry sections that are relevant to Excel 2002. You may not
find all these sections in your Registry database.
Table 4-4
Excel Configuration Information in the Registry
Section Description
Add-in Manager Lists add-ins that appear in the list box when you choose the Tools➪
Add-Ins command. Add-ins that are included with Excel do not appear
in this list. If you have an add-in entry in this list box that you no
longer use, you can remove it by using the Registry Editor.
Converters Lists additional (external) file converters that are not built into Excel.
AutoSave Holds the AutoSave option that you set.
Delete Commands Enables you to specify which menu commands you don’t want to
appear.
Error Checking Holds the settings for formula error checking.
Init Commands Holds information about custom commands.
Init Menus Holds information about custom menus.
Line Print Holds settings used in 1-2-3 macro printing. Excel updates this section
whenever it executes a 1-2-3 macro that has /wgdu (Worksheet

Global Default Update) in it.
Options A catch-all section; holds a wide variety of settings, including the paths
to files that are opened automatically when Excel starts (such as
add-ins).
Recent Files Stores the names of the last files saved (up to nine files).
Resiliency Information used for recovering documents.
Security Specifies the security level for opening files that contain macros.
Spell Checker Stores information about your spelling checker options.
UserInfo Information about the user.
WK? Settings Contains settings for opening and saving 1-2-3 files (for example,
whether to create an FMT or FM3 format file).
Note
4799-2 ch04.F 6/11/01 9:28 AM Page 76
77
Chapter 4 ✦ Understanding Excel’s Files
Although you can change most of the settings via Excel’s Options dialog box,
several other useful settings cannot be changed directly from Excel (but you can
use the Registry Editor to make changes).
One more warning is in order. Prior to making any changes to the Registry, refer to
the sidebar “Before You Edit the Registry . . . “
Summary
In this chapter, I discussed the files used and created by Excel. I described Excel
installation, various ways to load files automatically, Excel’s file extensions, and file
formats supported by Excel (including HTML format). I also discussed some of
Excel’s settings in the Windows Registry. Information in this chapter that’s particu-
larly relevant to application development and programming appears in more detail
in other chapters.
This chapter concludes Part I. Part II provides information about developing user-
oriented applications with Excel.
✦✦✦

Caution
4799-2 ch04.F 6/11/01 9:28 AM Page 77
4799-2 ch04.F 6/11/01 9:28 AM Page 78
Excel
Application
Development
T
his part contains only two chapters, but they are impor-
tant for readers who want to become effective Excel
power programmers. In Chapter 5, I present my views on
exactly what constitutes a spreadsheet application. Chapter 6
discusses the general steps involved in creating a spreadsheet
application with Excel.
✦✦✦✦
In This Part
Chapter 5
What Is a
Spreadsheet
Application?
Chapter 6
Essentials of
Spreadsheet
Application
Development
✦✦✦✦
PART
II
II
4799-2 PO2.F 6/11/01 9:28 AM Page 79
4799-2 PO2.F 6/11/01 9:28 AM Page 80

What Is a
Spreadsheet
Application?
I
n this chapter, I attempt to clarify how people use spread-
sheets in the real world. This is a topic that’s germane to
this entire book because it can help you determine how much
effort you should devote to a particular development project.
By the time you finish this chapter, you should have a pretty
good idea of what I mean by a “spreadsheet application.” And
after you’ve made it through the rest of the book, you’ll be
well on your way to developing your own spreadsheet appli-
cations with Excel. But first, let’s get down to the basics.
You’ve probably been working with spreadsheets for several
years, but chances are good that your primary focus has been
on simply generating spreadsheets to get the job done. You
probably never gave much thought to more global issues like
those discussed in this chapter: the different types of spread-
sheet users, how to classify various types of spreadsheets,
and even basic questions such as why people use spread-
sheets. If the title of this book attracted your attention, it’s
important for you to understand these issues so that you can
become an effective “power programmer.” I’ll first discuss the
concept of a spreadsheet application. This is, after all, the
desired result of your power-programming efforts.
Spreadsheet Applications
Programming, as it relates to spreadsheet use, is essentially
the process of building applications that use a spreadsheet
rather than a traditional programming language such as C,
Pascal, or BASIC. In both cases, however, these applications

will be used by other people — not the developer of the
application.
5
5
CHAPTER
✦✦✦✦
In This Chapter
A working definition
of a spreadsheet
application
The difference
between a
spreadsheet user and
a spreadsheet
developer
A system for
classifying
spreadsheet users to
help you
conceptualize who
the audience is for
your applications
A discussion of why
people use
spreadsheets
A taxonomy of the
basic types of
spreadsheets
✦✦✦✦
4799-2 ch05.F 6/11/01 9:28 AM Page 81

82
Part II ✦ Excel Application Development
For purposes of this book, a spreadsheet application is a spreadsheet file (or
group of related files) that is designed so that someone other than the developer
can perform useful work without extensive training. According to this definition,
most of the spreadsheet files you’ve developed probably wouldn’t qualify as
spreadsheet applications. You may have dozens or hundreds of spreadsheet files on
your hard drive, but it’s a safe bet that most of them aren’t really designed for oth-
ers to use.
A good spreadsheet application has the following characteristics:
✦ It enables the end user to perform a task that he or she probably would not be
able to do otherwise.
✦ It provides the appropriate solution to the problem. (A spreadsheet environ-
ment isn’t always the optimal approach.)
✦ It accomplishes what it is supposed to do. This may be an obvious prerequi-
site, but it’s not at all uncommon for applications to fail this test.
✦ It produces accurate results and is free of bugs.
✦ It uses appropriate and efficient methods and algorithms to accomplish
its job.
✦ It traps errors before the user is forced to deal with them. Note that errors
and bugs are not the same. Attempting to divide by zero is an error. Failure to
identify that error before it occurs is a bug.
✦ It does not allow the user to delete or modify important components acciden-
tally (or intentionally).
✦ Its user interface is clear and consistent, so the user always knows how to
proceed.
✦ Its formulas, macros, and user interface elements are well documented, allow-
ing for subsequent changes, if necessary.
✦ It is designed so that it can be modified in simple ways without making major
changes. A basic fact of life is that a user’s needs change over time.

✦ It has an easily accessible help system that provides useful information on at
least the major procedures.
✦ It is designed so that it is portable and runs on any system that has the proper
software (in this case, a copy of the appropriate version of Excel).
It should come as no surprise that it is possible to create spreadsheet applications
for many different usage levels, ranging from simple fill-in-the-blank templates to
extremely complex applications that use custom menus and dialog boxes and that
may not even look like spreadsheets.
4799-2 ch05.F 6/11/01 9:28 AM Page 82
83
Chapter 5 ✦ What Is a Spreadsheet Application?
The Developer and the End User
I’ve already used the terms developer and end user, terms you’ll see frequently
throughout this book. Because you’ve gotten this far, I think I can safely assume
that you’re either a spreadsheet application developer or a potential developer.
My definitions regarding developers and end users are simple. The person who
creates the spreadsheet application is the developer. For joint projects, there are
multiple developers (a development team). The person who uses the results of the
developer’s spreadsheet programming efforts is the end user (which I often shorten
to simply user). In many cases, there will be multiple end users, and often the devel-
oper is one of the users.
Who are developers? What do they do?
I’ve spent about 15 years trading methodologies and basically hanging out with the
motley crew of folks who call themselves spreadsheet developers. I divide them
into two primary groups:
✦ Insiders are developers who are intimately involved with the users and thor-
oughly understand their needs. In many cases, these developers are also
users of the application. Often, they developed the application in response to
a particular problem.
✦ Outsiders are developers who are hired to produce a solution to a problem. In

most cases, developers in this category are familiar with the business in gen-
eral, but not with the specifics of the application they are developing. In other
cases, these developers are employed by the company that requests the
application (but they normally work in a different department).
Some developers devote full time to development efforts. These developers may be
either insiders or outsiders. A fair number of consultants (outsiders) make a decent
living developing spreadsheet applications on a freelance basis.
Other spreadsheet developers don’t work full time at the task and may not even
realize they are developing spreadsheet applications. These developers are often
office computer gurus who seem to know everything about computers and soft-
ware. These folks often create spreadsheet applications as a way to make their lives
easier — the time spent developing a well-designed application for others can often
save hours of training time and can greatly reduce the time spent answering others’
questions.
4799-2 ch05.F 6/11/01 9:28 AM Page 83
84
Part II ✦ Excel Application Development
Spreadsheet developers are typically involved in the following activities, often
performing most or all of each task on their own:
✦ Determining the needs of the user
✦ Planning an application that meets these needs
✦ Determining the most appropriate user interface
✦ Creating the spreadsheet, formulas, macros, and user interface
✦ Testing the application under all reasonable sets of conditions
✦ Making the application relatively “bulletproof” (often based on results from
the testing)
✦ Making the application aesthetically appealing and intuitive
✦ Documenting the development effort
✦ Distributing the application to users
✦ Updating the application if and when it’s necessary

I discuss these activities in more detail in Chapter 6.
Developers must have a thorough understanding of their development environment
(in this case, Excel). And there’s certainly a lot to know when it comes to Excel. By
any standard, Excel is easy to use, but defining what’s easy to use depends on the
user. Developing nontrivial spreadsheet applications with Excel requires an in-depth
knowledge of formulas, functions, macros, custom dialog boxes, custom toolbars,
menu modifications, and add-ins. Most Excel users, of course, don’t meet these
qualifications and have no intention of learning these details — which brings me to
the next topic: classifying spreadsheet users.
Classifying spreadsheet users
Over the years, I’ve found that it’s often useful to classify people who use spread-
sheets (including both developers and end users) along two dimensions: their
degree of experience with spreadsheets and their interest in learning about
spreadsheets.
To keep things simple, each of these two dimensions has three levels. Combining
them results in nine combinations, which are shown in Table 5-1. In reality, only
seven segments are worth thinking about because both moderately experienced
and very experienced spreadsheet users generally have at least some interest in
spreadsheets (that’s what motivated them to get their experience). Users who
have a lot of spreadsheet experience and a low level of interest would make very
bad developers.
Cross-
Reference
4799-2 ch05.F 6/11/01 9:28 AM Page 84

×