1. Trang chủ
  2. » Công Nghệ Thông Tin

Excel 2002 Power Programming with VBA phần 2 pot

99 313 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 99
Dung lượng 872,85 KB

Nội dung

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 http://officeupdate.microsoft.com/downloadDetails/ 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 [...]... concludes Part I Part II provides information about developing useroriented applications with Excel ✦ ✦ ✦ 77 4799 -2 ch04.F 6/11/01 9 :28 AM Page 78 4799 -2 PO2.F 6/11/01 9 :28 AM Page 79 P Excel Application Development T his part contains only two chapters, but they are important for readers who want to become effective Excel power programmers In Chapter 5, I present my views on exactly what constitutes a spreadsheet... 5 -2 Table 5 -2 “Why Do You Use a Spreadsheet?” Reason Inexperienced Moderately or very experienced It reduces the amount of work I have to do 12% 100% It saves time 20 % 91% It makes my work look better 76% 82% It helps prevent calculation errors 76% 82% It can handle lots of different tasks 12% 82% It’s fun 12% 73% It’s the most appropriate tool for a particular task 8% 73% It makes good graphs 12% ... text to uppercase (without using formulas) The solution? Develop a text-handling utility that does exactly what you want 91 4799 -2 ch05.F 92 6/11/01 9 :28 AM Page 92 Part II ✦ Excel Application Development On the CD-ROM The Power Utility Pak is a collection of utility applications for Excel I developed these utilities to extend Excel s functionality These utilities work just like normal Excel commands You... file for Regedit for details 75 4799 -2 ch04.F 76 6/11/01 9 :28 AM Page 76 Part I ✦ Some Essential Background The Registry settings are updated automatically by Excel when Excel closes Note 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,... how to use it 68% 55% It’s the only way I know to perform a particular task 72% 36% It’s all set up for me 28 % 27 % Making nice columns is easier with a spreadsheet than with a word processor 60% 18% It was on my workstation when I came here 36% 18% I like the macros 0% 9% Everybody else does 32% 0% 4799 -2 ch05.F 6/11/01 9 :28 AM Page 87 Chapter 5 ✦ What Is a Spreadsheet Application? I certainly don’t... to get involved with the tab strip stuff The complexity is handled by an ActiveX control Because of this, the end user must have Office 20 00 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 Note This section was intended to provide a brief overview of the HTML feature in Excel 20 00 and 20 02 This topic is... 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 written to the Registry until Excel closes by normal means Table 4-4 lists the Registry sections that are relevant to Excel 20 02 You may not find all these sections in your Registry database Table 4-4 Excel Configuration Information in the Registry Section Description... HKEY_CURRENT_CONFIG Hardware information HKEY_DYN_DATA Information on installed devices Excel s settings Information used by Excel 20 02 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... application Chapter 6 discusses the general steps involved in creating a spreadsheet application with Excel A R T II ✦ ✦ ✦ ✦ In This Part Chapter 5 What Is a Spreadsheet Application? Chapter 6 Essentials of Spreadsheet Application Development ✦ ✦ ✦ ✦ 4799 -2 PO2.F 6/11/01 9 :28 AM Page 80 4799 -2 ch05.F 6/11/01 9 :28 AM Page 81 5 C H A P T E R What Is a Spreadsheet Application? I n this chapter, I attempt... 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 Note The remainder of the material in this section assumes that you’re familiar with HTML 4799 -2 ch04.F 6/11/01 9 :28 AM Page 71 Chapter 4 ✦ Understanding Excel s Files Next, open the HTML file . 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, 20 00, 20 02 4799 -2 ch04.F 6/11/01 9 :28 AM Page 67 68 Part I ✦ Some Essential. files The XLS workbook files produced by Excel 20 02 use the same file format as Excel 20 00 and Excel 97. These files cannot be opened by any version of Excel prior to Excel 97. You can, however, save. for Excel 4 workbook files (obsolete beginning with Excel 5 because all files are workbooks). XLK A backup file. Excel versions prior to Excel 20 00 used standard Windows Help files (*.hlp). Excel 20 00

Ngày đăng: 14/08/2014, 02:20

TỪ KHÓA LIÊN QUAN