Microsoft Outlook 2007 Programming

Book description

Microsoft Outlook is the most widely used e-mail program and offers the most programmability. Sue Mosher introduces key concepts for programming Outlook using Visual Basic for Applications, custom Outlook forms, and external scripts, without the need for additional development tools.

For those who manage Outlook installations, it demonstrates how to use new features in the Outlook 2007 programming model such as building scripts that can create rules and views and manage categories. Power users will discover how to enhance Outlook with custom features, such as the ability to process incoming mail and extract key information. Aimed at the non-professional programmer, it also provides a quick guide to Outlook programming basics for pro developers who want to dive into Outlook integration.

*Dozens of new programming objects detailed including views, rules, categories, searches

*No previous coding experience or additional development tools required

*Examples outline issues using real-world functionality

Table of contents

  1. Copyright
  2. Introduction
    1. Conventions used in this book
  3. Acknowledgments
  4. 1. What You Can Do with Outlook 2007
    1. 1.1. Why program with Outlook?
    2. 1.2. Outlook programming tools
      1. 1.2.1. Visual Basic for Applications
      2. 1.2.2. Custom Outlook forms
      3. 1.2.3. Visual Basic Scripting Edition
      4. 1.2.4. Folder home pages
      5. 1.2.5. Office integration and other object models
    3. 1.3. How to start
    4. 1.4. Key Outlook programming components
    5. 1.5. Showing developer commands
    6. 1.6. Summary
  5. I. Basic Outlook VBA Design
    1. 2. The VBA Design Environment
      1. 2.1. VBA: The basics
        1. 2.1.1. VBA security
        2. 2.1.2. Starting VBA
        3. 2.1.3. Saving your work and ending a VBA session
      2. 2.2. VBA windows
        1. 2.2.1. Project Explorer
        2. 2.2.2. Properties window
        3. 2.2.3. VBA user forms
        4. 2.2.4. Modules
        5. 2.2.5. Object Browser
      3. 2.3. Getting help in VBA
      4. 2.4. Working with VBA projects
        1. 2.4.1. Backing up your work
        2. 2.4.2. Signing your project
        3. 2.4.3. Distributing VBA code to others
      5. 2.5. Summary
    2. 3. Building Your First VBA Form
      1. 3.1. Understanding Outlook birthdays and anniversaries
      2. 3.2. Step 1: What controls do you need?
      3. 3.3. Step 2: Create the form
        1. 3.3.1. Exploring form properties
        2. 3.3.2. Should you use a modal or modeless form?
      4. 3.4. Step 3: Add user input controls
      5. 3.5. Step 4: Add command buttons
        1. 3.5.1. Basic command button properties
        2. 3.5.2. Adding code
        3. 3.5.3. Anatomy of a procedure
      6. 3.6. Step 5: Plan the next development stage
      7. 3.7. More on VBA form controls
        1. 3.7.1. Check box controls
        2. 3.7.2. Option buttons
        3. 3.7.3. List box and combo box controls
        4. 3.7.4. Accelerators and tab order
      8. 3.8. Summary
  6. II. Basic Outlook Form Design
    1. 4. Introducing Outlook Forms
      1. 4.1. Understanding the two types of custom forms
      2. 4.2. Starting the forms designer
      3. 4.3. The six standard Outlook forms
        1. 4.3.1. The contact form
        2. 4.3.2. The appointment form
        3. 4.3.3. The task form
        4. 4.3.4. The journal entry form
        5. 4.3.5. The message form
        6. 4.3.6. The post form
        7. 4.3.7. Additional forms
        8. 4.3.8. Common form pages
      4. 4.4. When to use which form
      5. 4.5. Working in the forms designer
        1. 4.5.1. Controls and the Control Toolbox
        2. 4.5.2. The Field Chooser
        3. 4.5.3. Getting forms design help
      6. 4.6. Saving forms and ending a design session
        1. 4.6.1. Understanding published forms
        2. 4.6.2. Understanding .oft form template files
      7. 4.7. Creating your first custom contact form
        1. 4.7.1. Adding fields
        2. 4.7.2. Rearranging controls
        3. 4.7.3. Showing, hiding, and renaming pages
        4. 4.7.4. Setting control properties
        5. 4.7.5. Testing the form
        6. 4.7.6. Setting form properties
        7. 4.7.7. Saving and publishing the form
        8. 4.7.8. Using the form
      8. 4.8. Summary
    2. 5. Introducing Form Regions
      1. 5.1. Understanding form regions
      2. 5.2. Controls for form regions
      3. 5.3. Creating your first form region
      4. 5.4. Registering and deploying form regions
        1. 5.4.1. Other form region manifest settings
        2. 5.4.2. Other considerations for deploying form regions
      5. 5.5. Limitations of form regions
      6. 5.6. Other ideas for form regions
      7. 5.7. Summary
    3. 6. Extending Form Design with Fields and Controls
      1. 6.1. Understanding fields versus controls
      2. 6.2. Creating user-defined fields
        1. 6.2.1. Field types
        2. 6.2.2. Combination fields
        3. 6.2.3. Formula fields
        4. 6.2.4. Working with formula and combination fields
        5. 6.2.5. Example: Calculate a contact’s age
      3. 6.3. Adding and removing fields on Outlook forms
        1. 6.3.1. Binding a control to a field
        2. 6.3.2. Initial value
        3. 6.3.3. Simple validation
        4. 6.3.4. Validation formulas
        5. 6.3.5. Validation formula messages
      4. 6.4. Using form controls
        1. 6.4.1. Text boxes
        2. 6.4.2. Command buttons
        3. 6.4.3. Check boxes
        4. 6.4.4. Option buttons
        5. 6.4.5. Frames
        6. 6.4.6. List box and combo box controls
        7. 6.4.7. Spin button
        8. 6.4.8. Multi-page control
        9. 6.4.9. Image control
        10. 6.4.10. Outlook View Control
        11. 6.4.11. Some control and field limitations
      5. 6.5. Laying out compose and read pages
      6. 6.6. Summary
  7. III. Writing VBA and VBScript Code
    1. 7. Outlook Code Basics
      1. 7.1. Understanding when VBA code runs
        1. 7.1.1. VBA form events
        2. 7.1.2. What is a Sub anyway?
        3. 7.1.3. Outlook VBA application-level events
        4. 7.1.4. Macros to run programs on demand
        5. 7.1.5. “Run a script” rule procedures
      2. 7.2. Writing VBA code
        1. 7.2.1. Variables
        2. 7.2.2. Outlook properties and methods
        3. 7.2.3. Subroutines versus functions
        4. 7.2.4. Operators
        5. 7.2.5. Referring to VBA forms and controls
      3. 7.3. Writing VBScript code for Outlook forms
        1. 7.3.1. Declaring constants and variables
        2. 7.3.2. Custom form events
        3. 7.3.3. Adding VBScript code to an Outlook form
        4. 7.3.4. Canceling events
        5. 7.3.5. Referring to Outlook form controls
      4. 7.4. Referring to Outlook item properties
        1. 7.4.1. Working with custom keywords properties
        2. 7.4.2. Creating custom properties programmatically
      5. 7.5. Writing other Outlook automation code
        1. 7.5.1. Starting an Outlook session
        2. 7.5.2. Limitations on Outlook automation
      6. 7.6. Summary
    2. 8. Code Grammar 101
      1. 8.1. Option Explicit
      2. 8.2. Declaring variables and constants
        1. 8.2.1. Variable data types
        2. 8.2.2. Variable naming conventions
        3. 8.2.3. Understanding scope
        4. 8.2.4. Declaring constants
      3. 8.3. Writing procedures
        1. 8.3.1. Calling procedures
        2. 8.3.2. Passing arguments
        3. 8.3.3. Adding data types to parameters and functions
        4. 8.3.4. Making code reusable
        5. 8.3.5. Documenting your procedures
        6. 8.3.6. More code style tips
      4. 8.4. Working with expressions and functions
        1. 8.4.1. Elements of an expression
        2. 8.4.2. Using mathematical expressions
      5. 8.5. Working with strings
        1. 8.5.1. Extracting string parts
        2. 8.5.2. Comparing strings
        3. 8.5.3. Replacing parts of a string
        4. 8.5.4. Other useful string functions
        5. 8.5.5. Example: Parsing text from a structured text block
      6. 8.6. Working with dates and times
        1. 8.6.1. Basic date-related functions
        2. 8.6.2. Date extraction functions
        3. 8.6.3. Performing date arithmetic
        4. 8.6.4. Time zones and international dates
      7. 8.7. Using arrays, dictionaries, and the Split() and Join() functions
        1. 8.7.1. Working with multidimensional arrays
        2. 8.7.2. Building and using dictionaries
        3. 8.7.3. Example: Parsing structured text with an array and a dictionary
      8. 8.8. Controlling program flow
        1. 8.8.1. If ... Then statements
        2. 8.8.2. Select Case statements
        3. 8.8.3. Do loops
        4. 8.8.4. For ... Next loops
        5. 8.8.5. Example: Handling multiselect list boxes
        6. 8.8.6. For Each ... Next loops for collections
        7. 8.8.7. GoTo statements
      9. 8.9. Providing feedback
        1. 8.9.1. Feedback with message boxes
        2. 8.9.2. Feedback with VBA forms
        3. 8.9.3. Example: Adding feedback to the birthday/anniversary reminder form
      10. 8.10. Getting user input
        1. 8.10.1. Using message boxes
        2. 8.10.2. Using input boxes
        3. 8.10.3. Using VBA forms
      11. 8.11. Working with files and other objects
        1. 8.11.1. Adding programming library references in VBA
        2. 8.11.2. Using the Scripting Runtime library
        3. 8.11.3. Using Windows Script Host techniques
      12. 8.12. Summary
    3. 9. Handling Errors, Testing, and Debugging
      1. 9.1. Understanding errors
        1. 9.1.1. Simple syntax errors
        2. 9.1.2. Compile errors
        3. 9.1.3. Runtime errors
        4. 9.1.4. Logic errors
        5. 9.1.5. Outlook bugs
      2. 9.2. Testing and debugging in VBA
        1. 9.2.1. Using breakpoints
        2. 9.2.2. Working in break mode
        3. 9.2.3. Using the Immediate window
        4. 9.2.4. Continuing program execution
        5. 9.2.5. Adding VBA error handlers
      3. 9.3. Debugging Outlook form VBScript code
        1. 9.3.1. Error handling in VBScript
        2. 9.3.2. Using the script debugger
        3. 9.3.3. Using VBA to prototype VBScript code
        4. 9.3.4. A recipe for VBA to VBScript code conversion
      4. 9.4. Summary
  8. IV. Fundamental Outlook Coding Techniques
    1. 10. Outlook Programming Basics
      1. 10.1. Introducing the Outlook object model
        1. 10.1.1. Launching the VBA Object Browser
        2. 10.1.2. Searching for objects and getting help
      2. 10.2. Outlook object and collection code techniques
        1. 10.2.1. Item method
        2. 10.2.2. Add method
        3. 10.2.3. Remove method
        4. 10.2.4. Example: Creating a voting button message
        5. 10.2.5. Releasing objects
      3. 10.3. Understanding Outlook security
        1. 10.3.1. Automation security
        2. 10.3.2. Form security
        3. 10.3.3. Attachment security
        4. 10.3.4. HTML message security
        5. 10.3.5. Folder home page security
      4. 10.4. Summary
    2. 11. Responding to Outlook Events in VBA
      1. 11.1. Application object events
        1. 11.1.1. Using the Startup, MAPILogonComplete, and Quit events
        2. 11.1.2. Using NewMail and NewMailEx to handle incoming mail
        3. 11.1.3. Using the ItemSend event
        4. 11.1.4. Using the ItemLoad event
      2. 11.2. Writing handlers for other object events
        1. 11.2.1. Handling events in ThisOutlookSession
        2. 11.2.2. Handling events in class modules
      3. 11.3. Explorers and Explorer events
        1. 11.3.1. Example: Controlling the state of new folder windows
        2. 11.3.2. Example: Setting a default folder view
      4. 11.4. Inspectors and Inspector events
        1. 11.4.1. Example: Start the journal timer automatically
        2. 11.4.2. Example: Set a reminder on new all-day events
      5. 11.5. Folders, Folder, and Items events
        1. 11.5.1. Limitations of Items events
        2. 11.5.2. Example: Adding birthday and anniversary reminders
      6. 11.6. Processing incoming mail
        1. 11.6.1. Using a “run a script” rule
        2. 11.6.2. Using Application.NewMailEx
        3. 11.6.3. Using Items.ItemAdd
      7. 11.7. Using the Application.Reminder and Reminders events
        1. 11.7.1. Example: Don’t snooze important reminders
        2. 11.7.2. Example: Processing messages and running other code on a schedule
      8. 11.8. Summary
    3. 12. Coding Key Custom Form Scenarios
      1. 12.1. Working with Outlook item events
        1. 12.1.1. Understanding item event order
        2. 12.1.2. Preventing the user from making changes in a folder view
        3. 12.1.3. Locking an item for changes
      2. 12.2. Responding to user input on forms
        1. 12.2.1. Using the PropertyChange and CustomPropertyChange events
        2. 12.2.2. Handling Click events from unbound controls
        3. 12.2.3. Example: Using option buttons to change a caption color
        4. 12.2.4. Example: Creating a hyperlink on an Outlook form
        5. 12.2.5. Performing validation in Outlook form code
        6. 12.2.6. Example: A custom contact form with required categories
      3. 12.3. Handling form and control state issues
        1. 12.3.1. Checking item state in the Open event
        2. 12.3.2. Storing and restoring control state
        3. 12.3.3. Handling state in a folder-based workflow
      4. 12.4. Summary
    4. 13. Working with Stores, Explorers, and Folders
      1. 13.1. Information store concepts
      2. 13.2. Information store techniques
        1. 13.2.1. Adding a Personal Folders .pst file store
        2. 13.2.2. Removing a .pst store
        3. 13.2.3. Renaming a .pst store
      3. 13.3. Working with Explorers
        1. 13.3.1. Basic view techniques for Explorer windows
        2. 13.3.2. Setting the currently displayed folder
      4. 13.4. Accessing folders
        1. 13.4.1. Getting a default folder
        2. 13.4.2. Getting the current folder
        3. 13.4.3. Letting the user choose a folder
        4. 13.4.4. Example: Setting the save folder for a message
        5. 13.4.5. Getting a default folder from another Exchange mailbox
        6. 13.4.6. Getting a search folder
        7. 13.4.7. Walking the folder tree to get any folder
        8. 13.4.8. Returning an Exchange public folder
        9. 13.4.9. Returning shared folders using the navigation pane
        10. 13.4.10. Recursing folders
      5. 13.5. Working with folders
        1. 13.5.1. Working with folder properties
        2. 13.5.2. Creating and deleting folders
        3. 13.5.3. Moving and copying folders
        4. 13.5.4. Sharing a folder
        5. 13.5.5. Adding an RSS feed, Web calendar, or SharePoint list
      6. 13.6. Summary
    5. 14. Using PropertyAccessor and StorageItem
      1. 14.1. Using the PropertyAccessor object
        1. 14.1.1. Example: Send a spam report
        2. 14.1.2. Where to find property schema names
        3. 14.1.3. Example: Set the default message class on a folder
        4. 14.1.4. Understanding PropertyAccessor versus UserProperties
        5. 14.1.5. PropertyAccessor limitations and errors
      2. 14.2. Using the StorageItem object
        1. 14.2.1. StorageItem limitations
        2. 14.2.2. Example: Clean up one-off folder views
      3. 14.3. Summary
    6. 15. Working with Inspectors and Items
      1. 15.1. Working with Inspectors
      2. 15.2. Creating items
        1. 15.2.1. Creating a new standard item
        2. 15.2.2. Creating a new item from a custom form
        3. 15.2.3. Creating a new item from an .oft template
        4. 15.2.4. Creating a new item from a vCard, iCalendar, or .msg file
        5. 15.2.5. Creating a new item from a Word or Excel document
      3. 15.3. Accessing items
        1. 15.3.1. Working with selected items
        2. 15.3.2. Getting the current item
        3. 15.3.3. Getting a particular item
        4. 15.3.4. Working with all the items in a folder
        5. 15.3.5. Example: Generate the next number in a sequence
      4. 15.4. Using the Table object
        1. 15.4.1. Example: Fill a list box from a Table
        2. 15.4.2. Example: Report on message response times
      5. 15.5. Using Item methods
      6. 15.6. Summary
    7. 16. Searching for Outlook Items
      1. 16.1. Introduction to Outlook search methods
      2. 16.2. Building search strings
        1. 16.2.1. Using the Jet search syntax
        2. 16.2.2. Using the DASL search syntax
        3. 16.2.3. Using the Query Builder
        4. 16.2.4. Searching for indexed content
        5. 16.2.5. Searching on item bodies, text, and keyword properties
        6. 16.2.6. Searching on date/time fields
        7. 16.2.7. Searching with custom properties
      3. 16.3. Using Items.Find and Items.Restrict
      4. 16.4. Using Table search techniques
      5. 16.5. Using Explorer.Search
      6. 16.6. Using Application.AdvancedSearch
        1. 16.6.1. Example: Update all birthday and anniversary events
        2. 16.6.2. Creating a new search folder
      7. 16.7. Summary
    8. 17. Working with Item Bodies
      1. 17.1. Basic item body techniques
      2. 17.2. Parsing text from a message body
      3. 17.3. Adding text to an item
        1. 17.3.1. Adding text to the Body property
        2. 17.3.2. Adding text to the HTMLBody property
      4. 17.4. Creating a formatted message
        1. 17.4.1. Creating an HTML-format message from a file
        2. 17.4.2. Creating a message from a boilerplate template
      5. 17.5. Using WordEditor
        1. 17.5.1. Moving around in the Word editor
        2. 17.5.2. Example: Boilerplate reply that includes incoming text
        3. 17.5.3. Inserting hyperlinks
        4. 17.5.4. Inserting pictures
      6. 17.6. Working with Outlook signatures
        1. 17.6.1. Creating a signature
        2. 17.6.2. Inserting the default signature
        3. 17.6.3. Removing signature text
      7. 17.7. Summary
    9. 18. Working with Recipients and Address Lists
      1. 18.1. Key recipient and address list objects
      2. 18.2. Understanding address lists
        1. 18.2.1. Displaying a contact folder as an address book
        2. 18.2.2. Example: Generate a report on Exchange users
      3. 18.3. Working with item recipients
        1. 18.3.1. Adding recipients
        2. 18.3.2. Example: Checking outgoing recipients
        3. 18.3.3. Example: Automatically add a Bcc recipient to an outgoing message
        4. 18.3.4. Understanding address resolution
      4. 18.4. Reading Recipient and AddressEntry information
        1. 18.4.1. Example: Create contacts for outgoing message recipients
        2. 18.4.2. Example: Respond to all the messages in a folder
      5. 18.5. Reading free/busy information
      6. 18.6. Showing the Select Names dialog
        1. 18.6.1. Example: Select contact links from a public folder
      7. 18.7. Summary
    10. 19. Working with Attachments
      1. 19.1. Understanding Outlook attachments
      2. 19.2. Adding attachments to Outlook items
        1. 19.2.1. Viewing attachments in the user interface
        2. 19.2.2. Creating a “freedoc” in an Outlook folder
      3. 19.3. Working with attachments on existing items
        1. 19.3.1. Saving attachments to the file system
        2. 19.3.2. Example: Import embedded Outlook items
        3. 19.3.3. Example: Reply with attachments
        4. 19.3.4. Opening attachments
        5. 19.3.5. Working with hidden attachments
      4. 19.4. Summary
    11. 20. Common Item Techniques
      1. 20.1. Using custom message forms
        1. 20.1.1. Controlling the settings for replies and forwards
        2. 20.1.2. Adding code to the Reply and Forward events
      2. 20.2. Working with voting buttons and other custom actions
        1. 20.2.1. Custom Action Properties
        2. 20.2.2. Writing code for custom actions
        3. 20.2.3. Example: A vacation approval form
        4. 20.2.4. Using command buttons with custom actions
      3. 20.3. Sending a message with a specific account
      4. 20.4. Creating a meeting request
      5. 20.5. Assigning a task
      6. 20.6. Linking Outlook items
        1. 20.6.1. Linking with a unique identifier
        2. 20.6.2. Understanding the Activities page
        3. 20.6.3. Using the Links collection
        4. 20.6.4. Example: Add a contact phone number to a task
      7. 20.7. Creating an annual event from a custom date field
      8. 20.8. Summary
  9. V. Finishing Touches
    1. 21. Deploying and Managing Outlook Forms
      1. 21.1. Understanding Outlook forms architecture
        1. 21.1.1. Understanding the forms cache
        2. 21.1.2. Launching a custom form
      2. 21.2. Managing Outlook forms
        1. 21.2.1. Making a custom form the new global default
        2. 21.2.2. Converting existing items to use a custom form
        3. 21.2.3. Importing to a custom form
      3. 21.3. Managing custom fields
        1. 21.3.1. Deploying custom fields
        2. 21.3.2. Best practices for adding fields to custom forms
      4. 21.4. Deploying Outlook forms
        1. 21.4.1. Distributing forms to remote users
        2. 21.4.2. Publishing a custom form programmatically
      5. 21.5. Troubleshooting Outlook forms
        1. 21.5.1. Understanding one-off forms
        2. 21.5.2. Dealing with forms cache problems
        3. 21.5.3. Recovering a form from the forms cache
      6. 21.6. Summary
    2. 22. Rules, Views, and Administrator Scripting Tasks
      1. 22.1. Why Outlook scripting is a challenge
      2. 22.2. Internal scripting with custom message forms
        1. 22.2.1. Deploying settings with a custom form
        2. 22.2.2. Using custom forms to generate reports
      3. 22.3. Working with Outlook rules
        1. 22.3.1. Creating new rules
        2. 22.3.2. Running rules programmatically
      4. 22.4. Managing folder views
        1. 22.4.1. Setting view properties
        2. 22.4.2. Example: Create category-filtered views
        3. 22.4.3. Managing public folder views
      5. 22.5. Internal scripting with folder home pages
      6. 22.6. Summary
    3. 23. Menus, Toolbars, and the Navigation Pane
      1. 23.1. Programming Outlook menus and toolbars
        1. 23.1.1. Working with submenus and other controls
        2. 23.1.2. Executing a toolbar command
        3. 23.1.3. Adding a new Explorer toolbar and controls
      2. 23.2. Working with context menus
        1. 23.2.1. Example: Display a store’s data location
        2. 23.2.2. Example: Find related items
      3. 23.3. Working with the navigation pane and other Explorer panes
        1. 23.3.1. Showing and hiding panes
        2. 23.3.2. Working with navigation pane modules
        3. 23.3.3. Example: Show a favorite Contacts folder first
      4. 23.4. Summary
    4. 24. Generating Reports on Outlook Data
      1. 24.1. Built-in report techniques
        1. 24.1.1. Printing from customized folder views
        2. 24.1.2. Copying data to Excel
        3. 24.1.3. Performing a Word mail merge
      2. 24.2. Coding reports with the Outlook object model
      3. 24.3. Sending output to Microsoft Excel
        1. 24.3.1. Understanding Excel report basics
        2. 24.3.2. Building a distribution list report
        3. 24.3.3. Formatting Outlook data for Excel
      4. 24.4. Sending output to Microsoft Word
        1. 24.4.1. Understanding Word report basics
        2. 24.4.2. Formatting Outlook data for Word
      5. 24.5. Using Word to build an invoice report
        1. 24.5.1. Building the invoice template
        2. 24.5.2. Coding the invoice report
        3. 24.5.3. Possible enhancements for the invoice report
      6. 24.6. Summary

Product information

  • Title: Microsoft Outlook 2007 Programming
  • Author(s):
  • Release date: July 2007
  • Publisher(s): Digital Press
  • ISBN: 9780080548739