Professional Outlook 2007 Programming Programmer to Programmer 1st Edition Ken Slovak instant download
Professional Outlook 2007 Programming Programmer to Programmer 1st Edition Ken Slovak instant download
https://ebookname.com/product/professional-
outlook-2007-programming-programmer-to-programmer-1st-edition-
ken-slovak/
https://ebookname.com/product/professional-oracle-programming-
programmer-to-programmer-1st-edition-rick-greenwald/
https://ebookname.com/product/professional-multicore-programming-
design-and-implementation-for-c-developers-wrox-programmer-to-
programmer-1st-edition-cameron-hughes/
https://ebookname.com/product/professional-ajax-2nd-edition-
programmer-to-programmer-nicholas-c-zakas/
https://ebookname.com/product/using-drupal-2nd-edition-angela-
byron/
Practical Handbook for Healthcare Epidemiologists 2nd
Edition Ebbing Lautenbach
https://ebookname.com/product/practical-handbook-for-healthcare-
epidemiologists-2nd-edition-ebbing-lautenbach/
https://ebookname.com/product/feed-your-family-right-how-to-make-
smart-food-and-fitness-choices-for-a-healthy-lifestyle-1st-
edition-elisa-zied/
https://ebookname.com/product/modern-america-1964-present-
discovering-u-s-history-1st-edition-tim-mcneese/
https://ebookname.com/product/the-cavalry-of-the-roman-
republic-1st-edition-jeremiah-b-mccall/
https://ebookname.com/product/applied-combinatorics-second-
edition-fred-s-roberts/
Catholic Social Learning Educating the Faith That Does
Justice 1st Edition Roger Bergman
https://ebookname.com/product/catholic-social-learning-educating-
the-faith-that-does-justice-1st-edition-roger-bergman/
49945ffirs.qxd:WroxPro 8/27/07 4:46 PM Page iii
Professional
Outlook® 2007 Programming
Ken Slovak
Professional
Outlook® 2007 Programming
49945ffirs.qxd:WroxPro 8/27/07 4:46 PM Page ii
49945ffirs.qxd:WroxPro 8/27/07 4:46 PM Page iii
Professional
Outlook® 2007 Programming
Ken Slovak
ISBN-13: 978-0-470-04994-5
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any
means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections
107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or
authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood
Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be
addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317)
572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRE-
SENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED
OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED
HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING
THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFES-
SIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFES-
SIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE
FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO
IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT
MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR
WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE
THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN
WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department within
the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress
are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and
other countries, and may not be used without written permission. Outlook and Microsoft are registered trademarks
of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their
respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be avail-
able in electronic books.
49945ffirs.qxd:WroxPro 8/27/07 4:46 PM Page v
This book is dedicated, as always, to my beloved wife, Susie, for her patience in putting up
with the long hours of writing and for just being there, and to my dog Casey for keeping me
company while I was writing this book and for being my sales manager and the administrator
of my Exchange server.
49945ffirs.qxd:WroxPro 8/27/07 4:46 PM Page vi
Credits
Acquisitions Director Production Manager
Jim Minatel Tim Tate
Acknowledgments
A book like this is a team effort, and even though only the author’s name is on the cover, everyone
on the team makes valuable contributions. I’d like to thank the editors at Wrox for all their work on
the book, which I appreciate more than I can ever express, and for their patience during the long
waits for new chapters. Maureen Spears has been a patient and painstaking development editor,
guiding the book from beginning to end. Jim Minatel, the acquisitions editor is an old friend and
also has been a patient and critical part of this book’s publication. Everyone else at Wrox has also
been great to work with. The technical editor, Diane Poremsky, an Outlook MVP, is an old friend
and writing partner, and I was lucky to have her on this book. The editors are responsible for
everything that’s correct in this book and nothing that's incorrect.
I constantly learn more about Outlook and Outlook development from my fellow Outlook
MVPs, especially the ones who also are involved with Outlook development: Sue Mosher,
Dmitry Streblechenko, Dave Kane, Jay Harlow, Eric Legault, Michael Bauer, Roberto Restelli, and
Ricardo Silva. I’d also like to thank the other Outlook and Exchange MVPs for everything I’ve
learned from them. There is no better group of MVPs and people, and I appreciate being included
in their company. I’d also like to thank Patrick Schmid, who although not an Outlook MVP hangs
out with us and who has done a lot of pioneering work with Ribbon development for Office 2007.
I’d also like to give special thanks to the people on the Outlook product team responsible for Outlook
programmability, Randy Byrne and Ryan Gregg. Randy is an old friend and former Outlook MVP
who has helped bring Outlook from the programming Dark Ages by enhancing the Outlook object
model to turn it into a complete programming API. Ryan has always been completely helpful and
responsive also, and has become a new friend. Finally, Bill Jacob, an Outlook premier support pro-
gramming specialist in Microsoft PSS, has always been another helpful friend.
49945ftoc.qxd:WroxPro 8/27/07 4:47 PM Page ix
Contents
Acknowledgments viii
Introduction xv
Contents
Chapter 3: Outlook Development 39
The Application Object 39
New Methods, Properties, and Events 44
Other Important Collections, Methods, Properties, and Events 48
The NameSpace Object 53
Exchange 53
Categories 54
Picking Folders 54
Picking Names 55
Summary 57
x
49945ftoc.qxd:WroxPro 8/27/07 4:47 PM Page xi
Contents
xi
49945ftoc.qxd:WroxPro 8/27/07 4:47 PM Page xii
Contents
Template Utility Code 179
VB.NET Utility Code 180
C# Utility Code 182
Displaying Outlook Property Pages 185
Displaying Property Pages with VB.NET 185
Displaying Property Pages with C# 186
Communicating with a COM Addin 188
VB.NET 188
Testing Addin Communications 189
C# 190
VSTO with VB.NET 191
VSTO with C# 194
Summary 196
xii
49945ftoc.qxd:WroxPro 8/27/07 4:47 PM Page xiii
Contents
xiii
49945ftoc.qxd:WroxPro 8/27/07 4:47 PM Page xiv
Contents
C# OutInsp 345
VB InspWrap 347
C# InspWrap 353
VB TaskPane 362
C# TaskPane 366
VB Ribbon XML 372
C# Ribbon XML 373
Summary 373
xiv
49945flast.qxd:WroxPro 8/27/07 4:48 PM Page xv
Introduction
Welcome to Professional Programming Outlook 2007. This book covers Outlook programming, with the pri-
mary emphasis on the many new Outlook 2007 programming features. Existing knowledge of Outlook
programming isn’t necessary because this book teaches you all you need to know to develop everything
from Outlook custom forms and personal productivity macros to advanced COM addins that utilize a
range of Microsoft technologies.
When I first was briefed on the programming features of Outlook 2007 early in 2005, I felt like a kid at
Christmas. Finally, the Outlook object model had almost all the features Outlook developers had been
requesting for many years.
Outlook’s object model always has been incomplete. Many properties that are important to Outlook
developers were always unavailable in previous versions of the Outlook object model. Some examples of
properties that were unavailable are Internet headers in emails, the name of the last person to modify an
item, the global object ID for calendar items that was introduced in Outlook 2003 SP2 and calendar labels.
Advanced Outlook programming always had to use additional programming APIs such as CDO 1.21
(Collaboration Data Objects), Extended MAPI, and third-party libraries that exposed Extended MAPI
properties, such as Redemption, that weren’t in the Outlook object model.
Now, with Outlook 2007 you rarely if ever have to leave the Outlook object model to do what you want
with your code.
Most of the code samples in this book only require Outlook 2007, and use Outlook VBA code. Code that
utilizes COM addins or that uses VSTO requires you to install Visual Studio 2005 plus VSTO 2005 SE.
Introduction
❑ Importing data into Outlook from other programs such as Word, Excel, and Access.
❑ Exporting Outlook data into other programs such as Word, Excel, and Access.
❑ Custom user interface elements for Outlook such as menu items, toolbars, and custom Ribbon
elements, and the use of custom data input and output forms.
❑ Tips and tricks to make your Outlook code run faster and better.
Most short code snippets are presented in VBA (Visual Basic for Applications) code. VBA is useful as a
prototyping tool, and code in VBA is easily translated into VB.NET, VBScript, VB 6, and usually even
into C#. Longer code segments are presented in either VBA or in both VB.NET and C#. The case study is
presented using VB.NET and C#.
Each chapter introduces important Outlook programming concepts, with plenty of sample code to help
you make use of the new and old features of the Outlook object model. In more detail, here’s what you’ll
find in each chapter:
❑ Chapter 1 introduces you to Outlook 2007 programming and includes how to set up Outlook
VBA, how to delve into Outlook and the basics on data storage and data display.
❑ Chapter 2 covers what’s new in the Outlook object model for Outlook 2007, providing an overview
of the important new properties, methods and events in the new unified object model. The chapter
also covers new features that can dramatically improve the speed of Outlook code, the essentials
of Outlook code security, Outlook syntax, and new features for Outlook forms.
❑ Chapter 3 gives you the basics of Outlook development, starting with the decisions about
whether to develop using custom Outlook forms, macros or COM addins. It also covers the
essential elements of Outlook programming, including the Application, Namespace, Explorer and
Inspector objects and collections, Outlook collections and items, and using Outlook’s built-in
dialogs.
❑ Chapter 4 takes a look at Outlook VBA and macros. Outlook VBA isn’t only for creating simple
macros; it’s a great prototyping tool for almost any Outlook project. The VBA Project, macro
security, class modules, UserForms, event handling, macro projects and macro distribution are
among the topics covered here.
❑ Chapter 5 covers Outlook forms, with custom forms both with and without code. The newly
exposed form controls such as the calendar controls are discussed, as is prototyping Outlook
forms code using VBA, Outlook form publishing and custom form distribution.
❑ Chapter 6 shows you Outlook COM addins, both managed and unmanaged, as well as how to
use VSTO 2005 SE (Visual Studio Tools for Office) to simplify the development of managed
Outlook addins. Creating Outlook property pages, debugging Outlook COM addins and distri-
bution of COM addins are also covered.
❑ Chapter 7 covers customizing the Outlook user interface. Working with menus and toolbars as
well as the new Office Ribbon interface are covered, as are custom views, custom task panes and
form regions.
❑ Chapter 8 shows how to interface Outlook with other applications. Interfacing with Word,
Excel, Access are all shown.
xvi
49945flast.qxd:WroxPro 8/27/07 4:48 PM Page xvii
Introduction
❑ Chapter 9 discusses real world Outlook programming tips and tricks. Code optimization for
speed, support for multiple versions of Outlook, working around Outlook’s remaining pro-
gramming limitations, coping with Outlook security and working with alternate APIs are all
covered from the perspective of an Outlook developer.
The rest of the material in the book gives you important learning and reference resources in the form of a
chapter devoted to a COM addin case study as well as two appendixes. The study chapter shows how to
use Outlook code in solving a real-world programming problem.
❑ Chapter 10 creates a task management system that utilizes the new PropertyAccessor and a
custom task pane to provide hierarchical task linking.
❑ Appendix A provides a summary of the important features of the Outlook 2007 object model.
Important new collections, events, methods, and properties are all covered, as are common
property tags used with the new PropertyAccessor object.
❑ Appendix B covers Outlook development resources, such as Microsoft and third-party Web
sites, resources for Outlook programming code samples, and tools that are useful for Outlook
development. It also shows you how to get help and support for Outlook development, cover-
ing Microsoft and third-party Web sites, support newsgroups, and support mailing lists.
Conventions
To help you get the most from the text and keep track of what’s happening, we’ve used a number of con-
ventions throughout the book.
Boxes like this one hold important, not-to-be forgotten information that is
directly relevant to the surrounding text.
Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
xvii
49945flast.qxd:WroxPro 8/27/07 4:48 PM Page xviii
Introduction
❑ We present code in two different ways:
In code examples we highlight new and important code with a gray background.
The gray highlighting is not used for code that’s less important in the
present context, or has been shown before.
Source Code
As you work through the examples in this book, you may choose either to type in all the code manually
or to use the source code files that accompany the book. All of the source code used in this book is avail-
able for downloading at www.wrox.com. The code for the addin templates and the chapters is also available
for downloading at www.slovaktech.com. Once at the site, simply locate the book’s title (either by using
the Search box or by using one of the title lists), and click the Download Code link on the book’s detail
page to obtain all the source code for the book.
Because many books have similar titles, you may find it easiest to search by ISBN; this book’s
097804470049945.
Once you download the code, just decompress it with your favorite compression tool. Alternately, you
can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to
see the code available for this book and all other Wrox books.
You can copy the VBA examples in this book into a code module in the Outlook VBA project and run
them to display the outputs for the email Internet message header and the Out of Office state. To enter
and run the code in VBA by copying it from the book:
Errata
We make every effort to ensure that there are no errors in the text or in the code. However, no one is per-
fect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece
of code, we would be very grateful for your feedback. By sending in errata you may save another reader
hours of frustration, and at the same time you will be helping us provide even higher-quality information.
xviii
49945flast.qxd:WroxPro 8/27/07 4:49 PM Page xix
Introduction
To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or
one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can
view all errata that has been submitted for this book and posted by Wrox editors. A complete book list,
including links to each book’s errata, is also available at www.wrox.com/misc-pages/booklist.shtml.
If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml
and complete the form there to send us the error you have found. We’ll check the information and, if
appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of
the book.
p2p.wrox.com
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based
system for you to post messages relating to Wrox books and related technologies and interact with other
readers and technology users. The forums offer a subscription feature to email you topics of interest of
your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts,
and your fellow readers are present on these forums.
xix
49945flast.qxd:WroxPro 8/27/07 4:49 PM Page xx
Introduction
At http://p2p.wrox.com you will find a number of different forums that will help you not only as you
read this book but also as you develop your own applications. To join the forums, just follow these steps:
You can read messages in the forums without joining P2P, but in order to post your own messages, you
must join.
Once you join, you can post new messages and respond to messages other users post. You can read mes-
sages at any time on the Web. If you would like to have new messages from a particular forum emailed
to you, click the Subscribe to this Forum icon by the forum name in the forum listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to ques-
tions about how the forum software works as well as many common questions specific to P2P and Wrox
books. To read the FAQs, click the FAQ link on any P2P page.
xx
49945flast.qxd:WroxPro 8/27/07 4:49 PM Page xxi
Professional
Outlook® 2007 Programming
49945flast.qxd:WroxPro 8/27/07 4:49 PM Page xxii
49945c01.qxd:WroxPro 8/27/07 4:53 PM Page 1
An Introduction to
Outlook 2007 Programming
Outlook stores items such as mail, appointment, task, and contact items in tables in a hierarchically
structured database. This is unlike the underlying document object model that most other Office appli-
cations use and requires a change of orientation for programmers experienced in programming
applications, such as Word or Excel. For this reason, this chapter explains Outlook’s data model
and introduces Outlook’s data storage and data presentation models.
In this chapter, you first open the Outlook VBA project and set it up for use in creating and running
macros and prototype code. Using the Outlook VBA project is often the easiest way to quickly test
and prototype your Outlook code. Next, you discover the concept of a NameSpace and how to access
Outlook data in folders and in individual Outlook items. This is the basis of all Outlook data
access and is a building block for all Outlook programming. You next see how Outlook stores its
data and how to access that data. In Outlook 2007, you can now access data either with the traditional
Folders and Items collections or with the new Stores collection and Table object. The new
members of the Outlook object model are explained in Chapter 2. Finally, this chapter discusses
Inspectors—the windows that display items such as emails or appointments, as well as Explorers—
the windows that display folders. Working with these collections is critical for any Outlook pro-
gram that works with the Outlook display.
166.1 Rolls of Parl. v. 285. It may be observed that the bishopric was at this
time vacant, and the dean, whose name was John Hals, had received a
papal provision to be the new bishop, but was forced to relinquish it in
favour of George Nevill, son of the Earl of Salisbury, a young man of only
three-and-twenty years of age. Godwin de Præsulibus. Le Neve’s Fasti.
Nicolas’s Privy Council Proceedings, vi. 265.
166.2 Rolls of Parl. v. 285.
166.3 Privy Council Proceedings, vi. 262.
167.1 Rolls of Parl. v. 285-7.
167.2 Ibid. v. 288-90.
167.3 Ibid. 321.
167.4 No. 322.
170.2 Lambeth MS. 211, f. 148. This letter is dated 24th August 1456.
170.3 Rymer, xi. 383.
171.1 Nos. 330, 331.
171.2 No. 334.
171.3 No. 331.
171.4 No. 348.
171.5 Tutbury was one of the possessions given to her for her dower. Rolls
of Parl. vi. 118.
172.1 Fabyan.
172.2 No. 345.
173.1 No. 348.
173.2 Accounts of the pageants shown before Queen Margaret at Coventry
are noticed as contained in the earliest Leet Book of the City. See Historical
MSS. Commission Report I., 100.
173.3 Privy Seals in Public Record Office.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com