You are previewing The Secret Life of Word.
O'Reilly logo
The Secret Life of Word

Book Description

A non-programmer's guide to Microsoft Word automation.

Table of Contents

  1. Preface
    1. Who Should Read This Book
      1. Word Versions
    2. How to Use This Book
    3. Book Structure
    4. Typographical Conventions
    5. Code Examples
    6. Help and More Information
    7. Acknowledgments
  2. Introduction To Word Automation
    1. Automation Overview
    2. Advantages of Automation
    3. Types of Automation
      1. Atomic Features
      2. Container Features
      3. Programmatic Features
    4. An Example of Automation
    5. How Do You Create Macros?
      1. Recording a macro
      2. Writing a macro
    6. Summary
  3. Creating Macros
    1. Recording a Macro
      1. The Developer Tab
      2. Using the Macro Recorder
    2. Playing Back a Macro
    3. Editing a Macro
      1. Using the <abbr xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="acronym">IDE</abbr>
    4. Deleting a Macro
    5. Accessing a Macro
      1. Button Method
      2. Keyboard Method
    6. Sharing A Macro
      1. Sharing Through Documents
      2. Sharing Through Templates
    7. Security
      1. Document Type
      2. Digital Signatures, Digital Certificates, and Trusted Publishers
      3. Security Level
      4. Trusted locations
    8. Documenting Macros for Others
    9. Advanced Features
      1. Creating Code
      2. IntelliSense
      3. Error Handling
        1. Compile errors
        2. Runtime errors
        3. Logic errors
      4. Debugging
        1. Stepping through code
        2. Watching variables
        3. Setting breakpoints
    10. Summary
  4. Find and Replace
    1. The Find Dialog
    2. GoTo Option
    3. Find and Replace Techniques
      1. The Boilerplate Approach
      2. The Three-Step Approach
    4. Special Characters
    5. Wildcards
      1. Examples of Wildcard Searches
      2. Placeholder Tags
      3. Placeholder Examples
    6. Multiple Searches
      1. Converting a Text File
      2. Cleaning Up Word's Bloated <abbr xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="acronym">HTML</abbr>
      3. Spell Checking an <abbr xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="acronym">HTML</abbr>//<abbr xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="acronym">XML</abbr> File File
      4. Converting a Database
    7. Calling Routines
    8. User Interaction
    9. Macros to Create Hyperlinks
    10. Regular Expressions
    11. Summary
  5. Fields, Form Fields, and Content Controls
    1. Fields
      1. Inserting Fields
        1. The Ribbon
        2. Field dialog
          1. Customizing fields
          2. Inserting customized fields
        3. Keyboard
      2. Field Management
      3. Updating Fields
        1. Field types
        2. Update events
          1. Explicit updates
          2. Opening a document
          3. Opening a document in print layout view
          4. Switching to print layout view or print preview
          5. Printing a document
          6. Pagination events
      4. Converting a Field to Text
      5. Locking Fields
      6. Viewing Field Codes
      7. Macros and VBA
        1. Updating fields with macros
          1. Updating specific fields
          2. Deleting fields
    2. Custom Fields
    3. Creating Custom Fields
    4. Field Functions
    5. Logical Operators
    6. Using Bookmarks with Fields
    7. Creating Bookmarks
      1. Creating a Bookmark Using Fields
      2. Using the Bookmark Dialog
      3. Showing or Hiding Bookmarks
      4. Using Bookmarks
      5. Creating Complex Fields
    8. Fields in Tables
      1. Programming Fields
      2. Using Find with Fields
      3. Creating Fields with VBA
      4. Field Shortcut Summary
    9. Form Fields
      1. Legacy Form Fields
        1. Creating legacy form fields
        2. Using legacy form fields
        3. Macros and legacy form fields
        4. Calculate on exit
        5. Gathering information
      2. Content Controls
        1. Creating content controls
        2. Customizing properties
        3. Locking controls, text, and documents
          1. Locking a control
            1. Locking and unlocking content controls
            2. Macro To find ranges with locked content controls
          2. Protecting an entire document
          3. Unprotecting an entire document
          4. Protecting parts of a document
          5. Unprotecting parts of a document
          6. Making a form
            1. Protecting a form document
            2. Unprotecting a form document
        4. Macros and VBA
        5. Gathering information
      3. Locking Text Outside a Content Control
      4. Unlocking Text Outside a Content Control
    10. Summary
  6. AutoCorrect and AutoText/Building Blocks
    1. AutoCorrect
      1. Adding Terms
      2. Math AutoCorrect
        1. Using a macro to add terms
    2. VBA, Macros, and AutoCorrect
    3. AutoText and Building Blocks
      1. Using AutoText
      2. Adding Templates
        1. Document template
        2. Global template
        3. Document building blocks template
      3. Inserting Text
        1. Building Block organizer
      4. Quick Parts Selection
      5. Entering the Name
      6. Defining Building Blocks
    4. Macros and VBA
      1. Listing Building Blocks
      2. Using VBA to Insert an Entry
      3. Listing All the Quick Parts Entries
      4. Listing All the AutoText Entries
      5. Sharing AutoText/Building Blocks
    5. Summary
  7. Smart Tags
    1. Understanding Smart Tags
    2. Managing Smart Tags
      1. Turning Smart Tags On or Off
      2. Showing or Hiding Smart Tag Marks
      3. Showing or Hiding Smart Tag Actions Buttons
      4. Saving or Discarding Smart Tags
      5. Saving Smart Tags as XML
      6. Removing Download URLs from Smart Tags
      7. Removing Smart Tags
      8. Re-applying Smart Tags
    3. Using Smart Tags
    4. Making Your Own Smart Tags
      1. Getting Started
      2. File Locations and Deploying Smart Tags
    5. Writing XML
      1. Using a Term List File
        1. Getting the Smart Tags SDK
        2. Creating a term list
        3. Compiling a term List
        4. Adding a term list
        5. Decompiling a term list
    6. Regular Expressions
    7. VBA and Smart Tags
    8. XML Reference
      1. Preface
        1. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;smartTagList&gt;</code> element element
          1. Example
        2. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;name&gt;</code> element element
          1. Example
        3. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;caption&gt;</code> element element
          1. Example
        4. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;description&gt;</code> element element
          1. Example
        5. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;moreInfoURL&gt;</code> element element
          1. Example
        6. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;LCID&gt;</code> element element
          1. Example
      2. Body
        1. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;smartTag&gt;</code> element element
        2. smartTag type Attribute
          1. Example
        3. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;terms&gt;</code> element element
          1. Example
        4. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;termlist&gt;</code> element element
          1. Example
        5. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;termfile&gt;</code> element element
          1. Example
        6. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;filename&gt;</code> element element
          1. Example
        7. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;re&gt;</code> element element
        8. Example
        9. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;exp&gt;</code> element element
          1. Example
        10. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;actions&gt;</code> element element
          1. Example
        11. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;action&gt;</code> element element
          1. Example
        12. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;caption&gt;</code> element element
          1. Example
        13. id Attribute
          1. Example
        14. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="sgmltag-starttag">&lt;url&gt;</code> element element
        15. Example
    9. Smart Tag Example
    10. Summary
  8. Exchanging Data
    1. Importing Information
      1. Copy and Paste Options
        1. Clipboard dialog
          1. Adding to the Office clipboard
          2. Viewing the Office clipboard
          3. Pasting from the Office clipboard
        2. Text formatting and copy/paste
        3. The Spike
      2. Macros and VBA for Copy and Paste
      3. Paste Special
      4. Dragging Text
        1. Link Here (link field)
        2. IncludeText field
        3. IncludePicture field
        4. Create shortcut here
      5. Open File
      6. Insert Object
        1. Editing or opening an object
        2. CSV and tab-delimited files
        3. XML
      7. Data Connection Wizard
        1. Inserting a new table from a database
        2. Setting query conditions
          1. Editing a table from a database
        3. Updating a table
        4. Using field codes
        5. Using macros and VBA to handle field codes
      8. Other Data Sources
    2. Mail Merge
      1. Creating a Mail Merge Letter
        1. Converting a date to a static field
        2. Formatting numbers and currency
        3. Using math with mail merge
        4. Using dates with mail merge
        5. Masking a US Social Security Number
        6. Including a picture
    3. Export
      1. Using Copy/Paste to Export Information
      2. Using Macros and VBA to Export Information
      3. Using Save As to Export Information
        1. Copying a table into a spreadsheet
      4. Saving Word Form Information to Excel
    4. Summary
  9. Code Samples
    1. Macro Structure
      1. Declaration Type
        1. Subroutine declarations
        2. Function declarations
    2. Scope
    3. Parameters
    4. Code Examples
      1. Assigning a Document
      2. Selection
      3. Copy
      4. Paste
      5. Delete
      6. Looping
        1. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="code">For...Next</code> loops loops
        2. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="code">For Each</code> loops loops
        3. <code xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" class="code">Do While</code> loops loops
      7. Tables
      8. Documents
      9. Revisions
      10. Fields
      11. Shapes
      12. Error Handling
    5. Comprehensive Example
    6. The Autos
      1. Examples of the Autos
    7. Special Characters
      1. Examples Using Special Characters
      2. Summary
  10. Automation Related Topics
    1. The Developer Tab
    2. How Do You Find Automation Projects?
      1. What Makes a Good Automation Project
      2. Planning for Automation
      3. Problems with Automation
      4. Programming Issues
        1. Handling errors
        2. Macros can't do everything
        3. Limited testing
        4. Others as users
      5. Microsoft Office-Related Issues
        1. Office has bugs
        2. Word can be slow
        3. Unexpected things
      6. User-Related Issues
        1. Unreliable formatting
        2. Users don't read messages
      7. How Do You Get Started?
    3. What is a Document Object Model?
    4. Why Not Use Selection?
    5. Tips for Using For Loops
    6. Don't Learn VBA With the Recorder
    7. Differences Between Word's Paragraph Marks and Carriage Returns
    8. Collecting Acronyms
  11. ASCII Table
    1. Control Characters: 0 – 31
    2. Basic ASCII codes: 32 – 127
    3. Extended ASCII codes: 128 – 255
    4. Code Examples
  12. Glossary
  13. Resources
  14. Index
  15. Copyright and Legal Notices