Mastering VBA for Microsoft Office 2007, 2nd Edition

Book description

Even if you're not a programmer, you can quickly learn to write macros, automate tasks, and create custom applications for Office 2007 with Microsoft's Visual Basic for Applications (VBA) and the in-depth instruction in this comprehensive guide. You'll jump right into the basics of recording and running macros with Office's built-in Macro Recorder, before quickly moving to the essentials of VBA syntax, using loops and functions, building effective code, and programming applications in Word, Excel, PowerPoint, Outlook, and Access. Includes pages of real-world examples and techniques.

Table of contents

  1. Cover
  2. Contents
  3. Title
  4. Copyright
  5. Dedication
  6. Acknowledgments
  7. About the Author
  8. Introduction
  9. Part 1: Recording Macros and Getting Started with VBA
    1. Chapter 1: Recording and Running Macros in the Microsoft Office Applications
      1. What is VBA and What Can You Do with It?
      2. Understanding Macro Basics
      3. Recording a Macro
      4. Running a Macro
      5. Recording a Sample Word Macro
      6. Recording a Sample Excel Macro
      7. Assigning a Way of Running the Macro
      8. Deleting a Macro
      9. The Bottom Line
    2. Chapter 2: Getting Started with the Visual Basic Editor
      1. Opening the Visual Basic Editor
      2. Using the Visual Basic Editor’s Main Windows
      3. Setting Properties for a Project
      4. Customizing the Visual Basic Editor
      5. Closing the Visual Basic Editor and Returning to the Host Application
      6. The Bottom Line
    3. Chapter 3: Editing Recorded Macros
      1. Testing a Macro in the Visual Basic Editor
      2. Editing the Word Macro
      3. Editing the Excel Macro
      4. Editing a PowerPoint Macro
      5. The Bottom Line
    4. Chapter 4: Creating Code from Scratch in the Visual Basic Editor
      1. Setting Up the Visual Basic Editor for Creating the Procedures
      2. Creating a Procedure for Word
      3. Creating a Procedure for Excel
      4. Creating a Procedure for PowerPoint
      5. Creating a Procedure for Access
      6. The Bottom Line
  10. Part 2: Learning How to Work With VBA
    1. Chapter 5: Understanding the Essentials of VBA Syntax
      1. Getting Ready
      2. Procedures
      3. Statements
      4. Keywords
      5. Expressions
      6. Operators
      7. Variables
      8. Constants
      9. Arguments
      10. Objects
      11. Collections
      12. Properties
      13. Methods
      14. Events
      15. The Bottom Line
    2. Chapter 6: Working with Variables, Constants, and Enumerations
      1. Working with Variables
      2. Working with Constants
      3. Working with Enumerations
      4. The Bottom Line
    3. Chapter 7: Using Array Variables
      1. What is an Array?
      2. Declaring an Array
      3. Storing Values in an Array
      4. Multidimensional Arrays
      5. Declaring a Dynamic Array
      6. Redimensioning an Array
      7. Returning Information from an Array
      8. Erasing an Array
      9. Finding Out Whether a Variable is an Array
      10. Finding the Bounds of an Array
      11. Sorting an Array
      12. Searching Through an Array
      13. The Bottom Line
    4. Chapter 8: Finding the Objects, Methods, and Properties You Need
      1. What is an Object?
      2. Working with Collections
      3. Finding the Objects You Need
      4. Using Object Variables to Represent Objects
      5. The Bottom Line
  11. Part 3: Making Decisions and Using Loops and Functions
    1. Chapter 9: Using Functions
      1. What is a Function?
      2. Using Functions
      3. Using Functions to Convert Data from One Type to Another
      4. Using Functions to Manipulate Strings
      5. Using VBA’s Mathematical Functions
      6. Using VBA’s Date and Time Functions
      7. Using File-Management Functions
      8. The Bottom Line
    2. Chapter 10: Creating Your Own Functions
      1. Components of a Function
      2. Creating a Function
      3. Examples of Functions for Any VBA-Enabled Application
      4. Creating a Function for Word
      5. Creating a Function for Excel
      6. Creating a Function for PowerPoint
      7. Creating a Function for Access
      8. The Bottom Line
    3. Chapter 11: Making Decisions in Your Code
      1. How Do You Compare Things in VBA?
      2. Testing Multiple Conditions by Using Logical Operators
      3. If Statements
      4. Select Case Statements
      5. The Bottom Line
    4. Chapter 12: Using Loops to Repeat Actions
      1. When Should You Use a Loop?
      2. Understanding the Basics of Loops
      3. Using For . . . Loops for Fixed Repetitions
      4. Using Do . . . Loops for Variable Numbers of Repetitions
      5. While . . . Wend Loops
      6. Nesting Loops
      7. Avoiding Infinite Loops
      8. The Bottom Line
  12. Part 4: Using Message Boxes, Input Boxes, and Dialog Boxes
    1. Chapter 13: Getting User Input with Message Boxes and Input Boxes
      1. Opening a Procedure to Work On
      2. Displaying Status Bar Messages in Word and Excel
      3. Message Boxes
      4. Input Boxes
      5. Forms: When Message Boxes and Input Boxes Won’t Suffice
      6. The Bottom Line
    2. Chapter 14: Creating Simple Custom Dialog Boxes
      1. When Should You Use a Custom Dialog Box?
      2. Creating a Custom Dialog Box
      3. Linking a Dialog Box to a Procedure
      4. Retrieving the User’s Choices from a Dialog Box
      5. Examples of Connecting Dialog Boxes to Procedures
      6. Using an Application’s Built-in Dialog Boxes from VBA
      7. The Bottom Line
    3. Chapter 15: Creating Complex Dialog Boxes
      1. Creating and Working with Complex Dialog Boxes
      2. Using Events to Control Forms
      3. The Bottom Line
  13. Part 5: Creating Effective Code
    1. Chapter 16: Building Modular Code and Using Classes
      1. Creating Modular Code
      2. Creating and Using Classes
      3. The Bottom Line
    2. Chapter 17: Debugging Your Code and Handling Errors
      1. Principles of Debugging
      2. The Different Types of Errors
      3. VBA’s Debugging Tools
      4. Dealing with Infinite Loops
      5. Dealing with Runtime Errors
      6. Suppressing Alerts
      7. Handling User Interrupts in Word, Excel, and Project
      8. Documenting Your Code
      9. The Bottom Line
    3. Chapter 18: Building Well-Behaved Code
      1. What is a Well-Behaved Procedure?
      2. Retaining or Restoring the User Environment
      3. Leaving the User in the Best Position to Continue Working
      4. Keeping the User Informed during the Procedure
      5. Making Sure the Procedure is Running under Suitable Conditions
      6. Cleaning Up after a Procedure
      7. The Bottom Line
    4. Chapter 19: Securing Your Code with VBA’s Security Features
      1. Understanding How VBA Implements Security
      2. Signing Your Macro Projects with Digital Signatures
      3. Choosing a Suitable Level of Security
      4. Locking Your Code
      5. The Bottom Line
  14. Part 6: Programming the Office Applications
    1. Chapter 20: Understanding the Word Object Model and Key Objects
      1. Examining the Word Object Model
      2. Working with the Documents Collection and the Document Object
      3. Working with the Selection Object
      4. Creating and Using Ranges
      5. Manipulating Options
      6. The Bottom Line
    2. Chapter 21: Working with Widely Used Objects in Word
      1. Using Find and Replace via VBA
      2. Working with Headers, Footers, and Page Numbers
      3. Working with Sections, Page Setup, Windows, and Views
      4. Working with Tables
      5. The Bottom Line
    3. Chapter 22: Understanding the Excel Object Model and Key Objects
      1. Getting an Overview of the Excel Object Model
      2. Understanding Excel’s Creatable Objects
      3. Working with Workbooks
      4. Working with Worksheets
      5. Working with the Active Cell or Selection
      6. Working with Ranges
      7. Setting Options
      8. The Bottom Line
    4. Chapter 23: Working with Widely Used Objects in Excel
      1. Working with Charts
      2. Working with Windows
      3. Working with Find and Replace
      4. Adding Shapes
      5. The Bottom Line
    5. Chapter 24: Understanding the PowerPoint Object Model and Key Objects
      1. Getting an Overview of the PowerPoint Object Model
      2. Understanding PowerPoint’s Creatable Objects
      3. Working with Presentations
      4. Working with Windows and Views
      5. Working with Slides
      6. Working with Masters
      7. The Bottom Line
    6. Chapter 25: Working with Shapes and Running Slide Shows
      1. Working with Shapes
      2. Working with Headers and Footers
      3. Setting Up and Running a Slide Show
      4. The Bottom Line
    7. Chapter 26: Understanding the Outlook Object Model and Key Objects
      1. Getting an Overview of the Outlook Object Model
      2. Working with the Application Object
      3. Understanding General Methods for Working with Outlook Objects
      4. Working with Messages
      5. Working with Calendar Items
      6. Working with Tasks and Task Requests
      7. Searching for Items
      8. The Bottom Line
    8. Chapter 27: Working with Events in Outlook
      1. Working with Application-Level Events
      2. Working with Item-Level Events
      3. The Bottom Line
    9. Chapter 28: Understanding the Access Object Model and Key Objects
      1. Getting Started with VBA in Access
      2. Getting an Overview of the Access Object Model
      3. Understanding Creatable Objects in Access
      4. Opening and Closing Databases
      5. Working with the Screen Object
      6. Using the DoCmd Object to Run Access Commands
      7. The Bottom Line
    10. Chapter 29: Manipulating the Data in an Access Database via VBA
      1. Understanding How to Proceed
      2. Preparing to Access the Data in the Database
      3. Opening a Recordset
      4. Accessing a Particular Record in a Recordset
      5. Searching for a Record
      6. Returning the Fields in a Record
      7. Editing a Record
      8. Inserting and Deleting Records
      9. Closing a Recordset
      10. The Bottom Line
    11. Chapter 30: Accessing One Application from Another Application
      1. Understanding the Tools for Communicating with Other Applications
      2. Using Automation to Transfer Information
      3. Using the Shell Function to Run an Application
      4. Using Data Objects to Store and Retrieve Information
      5. Communicating via DDE
      6. Communicating via SendKeys
      7. The Bottom Line
    12. Chapter 31: Programming the Office 2007 Ribbon
      1. Hiding the Editing Group on the Word Ribbon
      2. Working with Excel and PowerPoint
      3. Undoing Ribbon Modifications
      4. Selecting the Scope of Your Ribbon Customization
      5. Adding a New Group
      6. Adding Callbacks
      7. Adding Attributes
      8. Using Menus and Lists
      9. Toggling with a Toggle Button Control
      10. Modifying the Ribbon in Access
      11. Adding a Callback in Access
      12. What to Look For if Things Go Wrong
      13. Where to Go from Here
      14. The Bottom Line
  15. Appendix: The Bottom Line Solutions
  16. Glossary
  17. Index

Product information

  • Title: Mastering VBA for Microsoft Office 2007, 2nd Edition
  • Author(s): Richard Mansfield
  • Release date: April 2008
  • Publisher(s): Sybex
  • ISBN: 9780470279595