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

microsoft office excel 2003 programming inside out

590 920 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

Cấu trúc

  • Cover

    • Copyright page

  • Dedication

  • Contents at a Glance

  • Table of Contents

  • Acknowledgments

  • We’d Like to Hear from You

  • About the CD

    • What’s on the CD

    • Using the CD

    • System Requirements

    • Support Information

  • Conventions and Features Used in this Book

    • Text Conventions

    • Design Conventions

  • Part 1 Preliminaries

    • Chapter 1 What’s New in Excel 2003

      • Using Improved Statistical Functions

      • Creating Smart Documents

      • Creating Document Workspaces

      • Implementing Information Rights Management

      • Comparing Workbooks Side By Side

      • Getting Information with the Research Task Pane

      • Using Extended XML Capabilities

        • Creating Excel Lists

        • Mapping Excel Data to XML Schemas

        • Publishing Spreadsheets with Web Components

    • Chapter 2 Exploring Excel

      • Workbooks

      • Worksheets

      • Cells and Ranges

      • The Excel Interface

      • Formulas

  • Part 2 Visual Basic for Applications

    • Chapter 3 Exploring Visual Basic for Applications

      • An Overview of Object-Oriented Programming

        • Properties

        • Methods

        • Events

        • Collections

      • Working with Macros

        • Recording and Viewing Macros

        • Running a Macro

        • Debugging a Macro

        • Implementing Macro Security and Digital Signatures

    • Chapter 4 VBA Programming Starter Kit

      • Introducing the Visual Basic Editor

        • Opening the Visual Basic Editor

        • Recognizing Parts of the Visual Basic Editor

        • Customizing the Visual Basic Editor

      • Managing Code Windows

        • Handling Windows

        • Adding Code

        • Notes on Programming Style and Code Readability

      • Developing Projects with the Project Explorer

        • Creating VBA Modules

        • Deleting VBA Modules

        • Copying Modules Between Projects

      • Declaring Variables, Constants, and Data Types

        • Declaring Variables

        • Defining Data Types

        • Defining Constants

        • Handling Strings

        • Handling Dates and Times

        • Handling Variants and Data Type Conversions

        • Understanding Variable Scope and Lifetimes

      • Assigning Values to Variables

      • Working with Arrays

        • Creating an Array

        • Creating Multidimensional Arrays

      • Creating Dynamic Arrays

      • Writing to the Screen and Accepting Input

        • Creating a Message Box

        • Creating an Input Box

      • Defining Object Variables

      • Creating Custom Data Types

        • With...End With Command

      • Controlling Program Flow

        • Selection Statements

        • Loops

        • GoTo Statement

      • Error Handling

    • Chapter 5 Creating Sub and Function Procedures

      • Defining Sub Procedures

        • Defining the Scope of a Sub Procedure

        • Running a Sub Procedure from Within Another Procedure

        • Retaining Values Between Procedure Calls

      • Defining Function Procedures

        • Creating a Function Procedure

        • Running Function Procedures

        • Passing Arguments to Procedures

        • Passing Named Arguments

      • Organizing for Success

  • Part 3 The Excel Object Model

    • Chapter 6 The Application Object

      • Introducing the Application Object

        • Properties

        • Methods

    • Chapter 7 Workbooks and Worksheets

      • The Workbooks Collection

        • Creating New Workbooks

        • Opening Workbooks

        • Workbook Properties

        • Workbook Methods

        • Printing and Previewing Workbooks

      • The Sheets and Worksheets Collections

        • Properties

        • Methods

        • Worksheet Methods

    • Chapter 8 Ranges and Cells

      • Basic Range Manipulations

        • Finding the Active Range

        • Selecting a Range

      • Referring to Ranges

        • Referencing Ranges on the Active Worksheet

        • Referencing Ranges on an Inactive Worksheet

        • Referencing Cells in a Range

        • Referencing Cells Using the Offset Property

        • Defining a Range Using the Cells Property

        • Referencing Columns and Rows

        • Referencing Non-Contiguous Groups of Cells

      • Manipulating Groups of Cells

        • Resizing Cells Programmatically

        • Joining Two Ranges Together

        • Detecting Empty Cells

      • Using Named Ranges

        • Defining a Named Range

        • Changing Notation Styles

        • Reserved Range Names

        • Copying Data Between Ranges and Arrays

      • Getting Data Entry Right the First Time

  • Part 4 Advanced VBA

    • Chapter 9 Manipulating Data with VBA

      • Manipulating Text

        • Determining if the Value in a Cell Is Text

        • Preparing String Data for Processing

        • Determining the Number of Characters in a String

        • Concatenating Text from Two or More Cells or Variables

        • Returning the First or Last Several Characters from a String

        • Returning Characters from Arbitrary Positions in a String

        • Finding a String Within Another String

      • Manipulating Numbers

        • Performing Summary Calculations

        • Performing Financial Calculations

      • Manipulating Dates and Times

        • Time and Date Serial Numbers

        • Date and Time Functions

    • Chapter 10 Formatting Excel Objects

      • Using Excel Color Constants and the Color Palette

        • Manipulating the Current Excel Color Palette

        • Using the Excel Color Palette on the Web

      • Formatting Worksheet Elements

      • Formatting Fonts

      • Formatting Cells

      • Formatting Borders

    • Chapter 11 Creating Add-Ins and COM Add-Ins

      • Introducing Add-Ins

      • Using the Add-Ins dialog box

        • Installing an Add-In

        • Unloading an Add-In

      • Creating Excel Add-Ins

        • Creating an Add-In

        • Saving the Add-In

        • Installing the Add-In

      • Using the AddIns Collection

        • AddIns Collection

        • AddIn Object

      • Creating Automation and COM Add-Ins

        • Using the IDTExtensibility2 Interface

        • Registry Keys

      • Building an Automation Add-In with Visual Basic 6

        • Designing the Add-In

        • Registry Entries

      • Building a COM Add-In with Visual Basic .NET

        • Running the Shared Add-In Wizard

        • Modifying the Template

        • Installing the Add-In

    • Chapter 12 Understanding and Using Events

      • Enabling and Disabling Events

      • Workbook Events

        • Open Event

        • Activate Event

        • SheetActivate Event

        • NewSheet Event

        • BeforeSave Event

        • Deactivate Event

        • BeforePrint Event

        • BeforeClose Event

      • Worksheet Events

        • Change Event

        • SelectionChange Event

        • BeforeRightClick Event

      • Application Events

        • Turning on Application Event Monitoring

        • Detecting When a Workbook Is Opened

    • Chapter 13 Manipulating Files

      • Locating External Files

        • Returning All Files

        • Limiting the File Search

        • Finding Files with the FileDialog Dialog Box

      • Writing to an External File

      • Reading from an External File

      • Searching a File for a Value

    • Chapter 14 Developing Class Modules

      • What Is an Object?

      • What Is a Class?

      • What Are Properties?

      • What Are Methods?

      • What Are Events?

      • Introducing Class Modules

        • Accessing Objects

        • Declaring Objects

        • Objects and Nothing

        • Objects with Multiple Object Variables

      • Properties, Methods, and Events

        • Public vs. Private Properties, Methods, and Events

        • Properties

        • Methods

        • Events

      • Building a Class

        • Creating a Class Module

        • Defining Simple Properties

        • Defining Property Routines

        • Defining Methods

        • Defining Events

        • Defining Private Variables, Subroutines, and Functions

        • Special Events for Classes

        • Resolving References

      • Practical Class Design

        • A Simple Class

        • Extending a Simple Class

        • A Collection Class

        • A Class with Business Rules

  • Part 5 Manipulating Excel Objects

    • Chapter 15 Charts

      • Introducing Charts

        • Creating Embedded Charts or Chart Sheets

        • Defining the Chart Object Model

      • Manipulating Charts

        • Activating a Chart

        • Deactivating a Chart

        • Modifying a Chart’s Data Series

        • Modifying a Chart to Use Data from Arrays

        • Defining a Chart’s Labels

        • Formatting a Chart

        • Modifying All Charts in a Workbook

        • Printing Charts

      • Final Thoughts on Programming Charts

    • Chapter 16 PivotTables and PivotCharts

      • PivotTables and PivotCharts

        • Introducing PivotTables

        • Creating a PivotTable with the PivotTable Wizard

        • Introducing PivotCharts

        • Creating a PivotChart with the PivotTable Wizard

        • Online Analytical Processing (OLAP) Issues

      • PivotTable Objects

        • PivotTables Collection

        • PivotTable Object

        • PivotCaches Collection

        • PivotCache Object

        • PivotField Objects

        • PivotItem Object

      • Programming PivotTables

        • Creating a PivotTable

        • Creating a PivotChart

      • Manipulating PivotTables Programmatically

        • Pivoting a PivotTable Programmatically

        • Resetting a PivotTable to Its Original Position

        • Recording and Restoring Arbitrary PivotTable Positions

    • Chapter 17 Command Bars

      • Identifying Parts of the Menu System

        • CommandBars Collection

        • CommandBar Objects

        • Listing CommandBar Objects

        • Adding a Floating Command Bar

        • Deleting a Command Bar

      • Command Bar Controls

        • CommandBarControls Collection

        • CommandBarControl Object

        • Button Controls

        • Creating Toolbars

        • Combo Box Controls

        • Using a Combo Box

        • Pop-Up Controls

        • Displaying a Pop-Up

        • Adding Items to an Existing Menu

    • Chapter 18 Customizing Dialog Boxes

      • Displaying Existing Dialog Boxes

      • Modifying Existing Dialog Boxes

        • Exploring the Dialogs Collection

        • Passing Arguments to Existing Dialog Boxes

      • Planning with Dialog Boxes

    • Chapter 19 Creating User Forms

      • Creating a UserForm

        • Adding a UserForm

        • Designing a UserForm

        • Modifying a UserForm

        • Properties of a UserForm

        • Displaying a UserForm

      • UserForm Controls

        • Programming Controls

        • Common Properties, Methods, and Events

        • The Label Control

        • The CommandButton Control

        • The TextBox Control

        • The CheckBox Control

        • The ToggleButton Control

        • The SpinButton Control

        • The Frame Control

        • The OptionButton Control

        • The Image Control

        • The ScrollBar Control

        • The ListBox Control

        • The ComboBox Control

        • The RefEdit Control

        • The TabStrip Control

        • The MultiPage Control

    • Chapter 20 Creating Advanced User Forms

      • Capturing Information

        • Form Application Overview

        • Designing a Form

        • Displaying Data

        • Navigating The Worksheet

        • Editing Data

        • Adding Data

        • Validating Data

        • Displaying the User Form

      • Building a Multi-Step Wizard

        • Wizard Application Overview

        • Handling Menus

        • Building the UserForm

        • Navigating the Pages

        • Collecting Options for the Wizard

        • Summarizing the Options

        • Running the Wizard

  • Part 6 Excel and the Outside World: Collaborating Made Easy

    • Chapter 21 Excel and Other Office Applications

      • Starting Another Application

      • Activating Another Application

      • Binding

        • Late Binding

        • Early Binding

      • Interacting with Other Office Applications

        • Opening a Document in Word

        • Accessing an Active Word Document

        • Creating a New Word Document

        • Controlling Excel from Other Office Applications

      • Working with Multiple Applications to Get the Job Done

    • Chapter 22 Excel and the Structured Query Language

      • Comparing Spreadsheets and Databases

        • Fundamental Database Concepts

        • Database Keys

        • Accessing Databases from Excel

      • Manipulating Databases with SQL

      • The Select Statement

        • Simple Select Statements

        • Retrieving Rows

        • Sorting Rows

        • Using Multiple Tables

        • Using Functions

      • The Insert Statement

        • Using the Insert Statement

      • The Update Statement

      • The Delete Statement

    • Chapter 23 Introducing ADO

      • The ADO Object Model

        • Using the ADO Object Model

      • The Connection Object

        • Key Properties and Methods of the Connection Object

        • Connecting to Different Database Management Systems

        • Using the Errors Collection

        • Using the Error Object

      • The Command Object

        • Key Properties and Methods of the Command Object

        • Using the Parameters Collection

        • Using the Parameter Object

      • The Recordset Object

        • Key Properties and Methods of the Recordset Object

        • Using the Fields Collection

        • Using the Field Object

    • Chapter 24 Excel Query Program

      • Excel Query Program Overview

      • Setting Up the Project

      • Initializing the Program

      • Ending the Program

      • Connecting to a Database

        • Initializing the DBInfo UserForm

        • Changing Database Providers

        • Selecting Windows Authentication

        • Saving the Database Info

      • Editing a Query

      • Executing a Database Query

        • Getting the Information to Run the Query

        • Building a Connection String

        • Getting the Query

        • Running a Query

        • Copying Rows

      • Using the Excel Query Program

        • Configure the Connection Information

        • Enter a Query

        • Run the Query

    • Chapter 25 Excel and the Web

      • HTML

        • Saving a Worksheet as a Web Page

        • Publishing a Worksheet to the Web

        • Making Web-Based Worksheets Interactive

      • Using the Internet as a Data Source

        • Opening Web Pages as Workbooks

        • Using Web Queries

        • Parsing Web Pages for Specific Information

      • Using the Internet to Publish Results

        • Setting Up a Web Server

        • Saving Worksheets as Web Pages

        • Adding Interactivity with the Web Components

        • Communicating with a Web Server

      • Using Internet Solutions with Excel

    • Chapter 26 Excel and the Extensible Markup Language (XML)

      • Introducing Data Lists

        • Creating Data Lists Programmatically

      • Creating XML Schemas

      • Creating XML Data Files

      • Adding XML to a Workbook Manually

        • Importing XML Data Manually

      • Adding XML to a Worksheet Programmatically

        • Mapping a Schema to a Worksheet Programmatically

        • Mapping Schema Elements to Cells Using XPath

  • About the Authors

Nội dung

Cover.fm Page 1 Tuesday, January 13, 2004 4:23 PM www.it-ebooks.info PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2004 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Cataloging-in-Publication Data Frye, Curtis, 1968- Microsoft Office Excel 2003 Programming Inside Out / Curtis Frye, Wayne S. Freeze, Felicia K. Buckingham. p. cm. Includes index. ISBN 0-7356-1985-9 1. Microsoft Excel (Computer file) 2. Business Computer programs. 3. Electronic spreadsheets. I. Title. HF5548.4.M523F792 2003 005.54 dc22 2003064850 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 8 7 6 5 4 3 Distributed in Canada by H.B. Fenn and Company Ltd. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to mspinput@microsoft.com. ActiveX, BizTalk, DirectX, FrontPage, Hotmail, IntelliSense, MapPoint, Microsoft, Microsoft Press, MSDN, MSN, Outlook, PivotChart, PivotTable, PowerPoint, SharePoint, Tahoma, Visio, Visual Basic, Visual C++, Visual C#, Visual Studio, Windows, the Windows logo, Windows NT, and Windows Server are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions Editor: Juliana Aldous Project Editor: Dick Brown Technical Reviewer: Mark Dodge Indexer: Richard Shrout Body Part No. X10-09355 www.it-ebooks.info Microsoft Press Confidential masterpage = “blank” Inside Out (FrameMaker) sample pages jimkr To our families www.it-ebooks.info www.it-ebooks.info Contents at a Glance Part 1 Preliminaries 1€ Chapter 1 What’s New in Excel 2003 . . . . . . . 3 Chapter 2 Exploring Excel . . . . . . . . . . . . . . 13 Part 2 Visual Basic € for Applications 23€ Chapter 3 Exploring Visual Basic for Applications . . . . . . . . . . . . . . 25 Chapter 4 VBA Programming Starter Kit . . . . 41 Chapter 5 Creating Sub and Function Procedures . . . . . . . . . . . 85 Part 3 The Excel € Object Model 105€ Chapter 6 The Application Object . . . . . . . . 107 Chapter 7 Workbooks and Worksheets . . . . 129 Chapter 8 Ranges and Cells . . . . . . . . . . . . 161 Part 4 Advanced VBA 191€ Chapter 9 Manipulating Data with VBA. . . . 193 Chapter 10 Formatting Excel Objects . . . . . . 219 Chapter 11 Creating Add-Ins and COM Add-Ins . . . . . . . . . . . . . . . 239 Chapter 12 Understanding and Using Events . . . . . . . . . . . . . . . 265 Chapter 13 Manipulating Files . . . . . . . . . . . 281 Chapter 14 Developing Class Modules . . . . . 299 Part 5 Manipulating € Excel Objects 319€ Chapter 15 Charts . . . . . . . . . . . . . . . . . . . . 321 Chapter 16 PivotTables and PivotCharts. . . . 341 Chapter 17 Command Bars . . . . . . . . . . . . . 365 Chapter 18 Customizing Dialog Boxes . . . . . 383 v www.it-ebooks.info Contents At A Glance Chapter 19 Creating User Forms. . . . . . . . . . 395 Chapter 20 Creating Advanced User Forms . . . . . . . . . . . . . . . . . 419 Part 6 Excel and the € Outside World: € Collaborating € Made Easy 443€ Chapter 21 Excel and Other Office Applications . . . . . . . . . . . . . . . . 445 Chapter 22 Excel and the Structured Query Language . . . . 467 Chapter 23 Introducing ADO . . . . . . . . . . . . 481 Chapter 24 Excel Query Program . . . . . . . . . 497 Chapter 25 Excel and the Web . . . . . . . . . . . 519 Chapter 26 Excel and the Extensible Markup Language (XML) . . . . . . 539 vi www.it-ebooks.info Table of Contents Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix We’d Like to Hear from You . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi About the CD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii What’s on the CD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Using the CD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv Support Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv Conventions and Features Used in this Book . . . . . . . . . . . . . . . . . . . . . . . . xxv Text Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Design Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Part 1 Preliminaries Chapter 1 What’s New in Excel 2003 3 Using Improved Statistical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Creating Smart Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Creating Document Workspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Implementing Information Rights Management . . . . . . . . . . . . . . . . . . . . . . 7 Comparing Workbooks Side By Side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Getting Information with the Research Task Pane . . . . . . . . . . . . . . . . . . . . 8 Using Extended XML Capabilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Creating Excel Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Mapping Excel Data to XML Schemas . . . . . . . . . . . . . . . . . . . . . . . 10 Publishing Spreadsheets with Web Components . . . . . . . . . . . . . . . . 11 Chapter 2 Exploring Excel 13 Workbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Worksheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Cells and Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 The Excel Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 vii www.it-ebooks.info Table of Contents Part 2 Visual Basic for Applications Chapter 3 Exploring Visual Basic for Applications 25 An Overview of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . 25 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Working with Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Recording and Viewing Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Running a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Debugging a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Implementing Macro Security and Digital Signatures . . . . . . . . . . . . . 36 Chapter 4 VBA Programming Starter Kit 41 Introducing the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Opening the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Recognizing Parts of the Visual Basic Editor . . . . . . . . . . . . . . . . . . . 41 Customizing the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . . . . . 49 Managing Code Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Handling Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Adding Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Notes on Programming Style and Code Readability . . . . . . . . . . . . . . 54 Developing Projects with the Project Explorer . . . . . . . . . . . . . . . . . . . . . . 55 Creating VBA Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Deleting VBA Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Copying Modules Between Projects . . . . . . . . . . . . . . . . . . . . . . . . . 57 Declaring Variables, Constants, and Data Types . . . . . . . . . . . . . . . . . . . . 57 Declaring Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Defining Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Defining Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Handling Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Handling Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Handling Variants and Data Type Conversions. . . . . . . . . . . . . . . . . . 61 Understanding Variable Scope and Lifetimes . . . . . . . . . . . . . . . . . . 62 Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Working with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Creating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Creating Multidimensional Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Creating Dynamic Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 viii www.it-ebooks.info Table of Contents Writing to the Screen and Accepting Input . . . . . . . . . . . . . . . . . . . . . . . . 67 Creating a Message Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Creating an Input Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Defining Object Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Creating Custom Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 With End With Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Controlling Program Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Selection Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 GoTo Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Chapter 5 Creating Sub and Function Procedures 85 Defining Sub Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Defining the Scope of a Sub Procedure . . . . . . . . . . . . . . . . . . . . . . 90 Running a Sub Procedure from Within Another Procedure . . . . . . . . . 93 Retaining Values Between Procedure Calls . . . . . . . . . . . . . . . . . . . . 98 Defining Function Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Creating a Function Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Running Function Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Passing Arguments to Procedures . . . . . . . . . . . . . . . . . . . . . . . . . 101 Passing Named Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Organizing for Success . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Part 3 The Excel Object Model Chapter 6 The Application Object 107 Introducing the Application Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Chapter 7 Workbooks and Worksheets 129 The Workbooks Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Creating New Workbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Opening Workbooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Workbook Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Workbook Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Printing and Previewing Workbooks . . . . . . . . . . . . . . . . . . . . . . . . 147 ix www.it-ebooks.info Table of Contents The Sheets and Worksheets Collections . . . . . . . . . . . . . . . . . . . . . . . . . 149 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Worksheet Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Chapter 8 Ranges and Cells 161 Basic Range Manipulations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Finding the Active Range. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Selecting a Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Referring to Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Referencing Ranges on the Active Worksheet . . . . . . . . . . . . . . . . . 166 Referencing Ranges on an Inactive Worksheet . . . . . . . . . . . . . . . . 167 Referencing Cells in a Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Referencing Cells Using the Offset Property . . . . . . . . . . . . . . . . . . 167 Defining a Range Using the Cells Property . . . . . . . . . . . . . . . . . . . 172 Referencing Columns and Rows . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Referencing Non-Contiguous Groups of Cells . . . . . . . . . . . . . . . . . 172 Manipulating Groups of Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Resizing Cells Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Joining Two Ranges Together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Detecting Empty Cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Using Named Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Defining a Named Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Changing Notation Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Reserved Range Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Copying Data Between Ranges and Arrays . . . . . . . . . . . . . . . . . . . 185 Getting Data Entry Right the First Time . . . . . . . . . . . . . . . . . . . . . . . . . 187 Part 4 Advanced VBA Chapter 9 Manipulating Data with VBA 193 Manipulating Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Determining if the Value in a Cell Is Text . . . . . . . . . . . . . . . . . . . . 193 Preparing String Data for Processing . . . . . . . . . . . . . . . . . . . . . . . 195 Determining the Number of Characters in a String . . . . . . . . . . . . . 197 Concatenating Text from Two or More Cells or Variables . . . . . . . . . 198 Returning the First or Last Several Characters from a String . . . . . . 200 Returning Characters from Arbitrary Positions in a String . . . . . . . . . 202 Finding a String Within Another String . . . . . . . . . . . . . . . . . . . . . . 202 Manipulating Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Performing Summary Calculations . . . . . . . . . . . . . . . . . . . . . . . . . 206 Performing Financial Calculations . . . . . . . . . . . . . . . . . . . . . . . . . 208 x www.it-ebooks.info [...]... resources from Microsoft that will help you get the most out of Microsoft Office Excel 2003 and other business software from Microsoft ● Extending Excel In this section, you’ll find great information about third-party utilities and tools you use to further enhance your experience with Microsoft Office Excel 2003 The Companion CD provides detailed information about the files on this CD, and links to Microsoft. .. http://support .microsoft. com for help with any software issues xxi www.it-ebooks.info www.it-ebooks.info About the CD The Companion CD that ships with this book contains many tools and resources to help you get the most out of your Inside Out book What’s on the CD Your Inside Out CD includes the following: ● Complete eBook In this section, you’ll find an electronic version of Microsoft Office Excel 2003 Programming. .. Preliminaries Microsoft Office Excel 2003 Programming Inside Out Creating Smart Documents Chapter 1 Excel workbooks have always been able to interact with other Office documents, but those interactions have been somewhat limited Creating links to data on the Web, in a database, or in another Office document are all valuable abilities, but the workbook was simply a standalone collection of bits In Office 2003, ... of the file but don’t have Office 2003 or later installed on their computer will be able to use file viewers that let them examine the files, but not edit them Note Information Rights Management is only available in Microsoft Office Professional Edition 2003, Word 2003, Excel 2003, and PowerPoint 2003 Comparing Workbooks Side By Side Another useful new capability in Excel 2003 is the ability to scroll... New in Excel 2003 Chapter 1 document become available for every member of the team; if the changes conflict, you as the administrator are able to choose which changes will be adopted You can also use the controls on the Shared Workspace task pane to create and manage a document workspace Note Document workspaces are available for Microsoft Office Word 2003, Excel 2003, PowerPoint 2003, and Visio 2003. .. www.it-ebooks.info Part 1: Preliminaries Microsoft Office Excel 2003 Programming Inside Out Table 1-1 Improved Statistical Functions Chapter 1 BINOMDIST Determines the probability that a set number of true/false trials, where each trial has a consistent chance of generating a true or false result, will result in exactly a specified number of successes (for example, exactly five out of ten coin flips will end... Dodge, co-author of Microsoft Office Excel 2003 Inside Out, as my technical editor His knowledge of both the series and Excel gave him the perspective to make many terrific recommendations Lisa Pawlewicz, ably assisted by Jaime Odell, performed what was probably one of the more involved copy edits that has passed over their desks in a while Page proofs were handled by Sandi Resnick at Microsoft and the... you can filter the data, create a PivotTable, or add new rows to the list Whichever task you perform, Excel will shift the worksheet contents around the list to reflect the new entry (such as by adding a blank row 9 www.it-ebooks.info Part 1: Preliminaries Microsoft Office Excel 2003 Programming Inside Out Chapter 1 when you add data to a list) If you are working on a network equipped with SharePoint... what you think Tell us what you like about this book and what we can do to make it better When you write, please include the title and author of this book in your e-mail mes€ sage, as well as your name and contact information We look forward to hearing from you! How to Reach Us E-Mail: Mail: nsideout @microsoft. com Inside Out Series Editor Microsoft Press One Microsoft Way Redmond, WA 98052 Note: Unfortunately,... For box) to get more infor­ mation Figure 1-1 shows the Research task pane and a selection of the reference materials available for you 7 www.it-ebooks.info Part 1: Preliminaries Microsoft Office Excel 2003 Programming Inside Out Getting Information with the Research Task Pane Chapter 1 Figure 1-1 You can find synonyms, look up words in encyclopedias, and translate words into foreign languages using . any means without the written permission of the publisher. Library of Congress Cataloging-in-Publication Data Frye, Curtis, 1968- Microsoft Office Excel 2003 Programming Inside Out / Curtis. very fortunate to have Mark Dodge, co-author of Microsoft Office Excel 2003 Inside Out, as my technical editor. His knowledge of both the series and Excel gave him the perspective to make many. . 419 Part 6 Excel and the € Outside World: € Collaborating € Made Easy 443€ Chapter 21 Excel and Other Office Applications . . . . . . . . . . . . . . . . 445 Chapter 22 Excel and the Structured

Ngày đăng: 28/04/2014, 16:27

TỪ KHÓA LIÊN QUAN