Visual Studio Tools for Office 2007: VSTO for Excel, Word, and Outlook (Microsoft .NET Development Series) / Edition 2

Paperback (Print)
Buy New
Buy New from BN.com
$40.63
Used and New from Other Sellers
Used and New from Other Sellers
from $35.68
Usually ships in 1-2 business days
(Save 40%)
Other sellers (Paperback)
  • All (9) from $35.68   
  • New (6) from $35.68   
  • Used (3) from $49.95   

Overview

Visual Studio Tools for Office 2007: VSTO for Excel, Word, and Outlook is the definitive book on VSTO 2008 programming, written by the inventors of the technology. VSTO is a set of tools that allows professional developers to use the full power of Microsoft Visual Studio 2008 and the .NET Framework to program against Microsoft Office 2007.

This book delivers in one place all the information you need to succeed using VSTO to program against Word 2007, Excel 2007, and Outlook 2007, and provides the necessary background to customize Visio 2007, Publisher 2007, and PowerPoint 2007. It introduces the Office 2007 object models, covers the most commonly used objects in those object models, and will help you avoid the pitfalls caused by the COM origins of the Office object models. Developers who wish to program against Office 2003 should consult Carter and Lippert’s previous book, Visual Studio Tools for Office.

In VSTO 2008, you can build add-ins for all the major Office 2007 applications, build application-level custom task panes, customize the new Office Ribbon, modify Outlook’s user interface using Form Regions, and easily deploy everything you build using ClickOnce.

Carter and Lippert cover their subject matter with deft insight into the needs of .NET developers learning VSTO, based on the deep knowledge that comes from the authors’ unique perspective of living and breathing VSTO for the past six years. This book

  • Explains the architecture of Microsoft Office programming and introduces the object models
  • Covers the main ways Office applications are customized and extended
  • Explores the ways of customizing Excel, Word, and Outlook, and plumbs the depths of programming with their events and
    object models
  • Introduces the VSTO programming model
  • Teaches how to use Windows Forms and WPF in VSTO and how to work with the Document Actions Pane and application-level task panes
  • Delves into VSTO data programming and server data scenarios
  • Teaches ClickOnce VSTO deployment

This is the one book you need to succeed in programming against Office 2007.

C# and Visual Basic .NET Code samples for download can be found here: http://www.informit.com/store/product.aspx?isbn=0321533216

Read More Show Less

Editorial Reviews

From the Publisher
Praise for Visual Studio Tools for Office 2007

“Visual Studio Tools for Office has always been one of my favorite technologies to come out of Microsoft. There are millions of people who use Office applications all day, every day; with VSTO, you can create applications for them. Eric Carter and Eric Lippert helped create VSTO, so they know as much about it as anybody, making this book a must-have. After reading it, you’ll know everything needed to begin building solutions that take advantage of the .NET Framework features, in the UI your users are familiar with.”

–Robert Green, senior consultant, MCW Technologies

“With the application development community so focused on the Smart Client revolution, a book that covers VSTO from A to Z is both important and necessary. This book lives up to big expectations. It is thorough, has tons of example code, and covers Office programming in general terms–topics that can be foreign to the seasoned .NET developer who has focused on ASP.NET applications for years. Congratulations to Eric Lippert and Eric Carter for such a valuable work!”

–Tim Huckaby, CEO, InterKnowlogy; Microsoft Regional Director

“Eric Carter and Eric Lippert really get it. Professional programmers will love the rich power of Visual Studio and .NET, along with the ability to tap into Office programmability. This book walks you through programming Excel, Word, and Outlook solutions.”

–Vernon W. Hui, test lead, Microsoft Corporation

“This book is both a learning tool and a reference book, with a richness of tables containing object model objects and their properties, methods, and events. I would recommend it to anyone considering doing Office development using the .NET Framework; especially people interested in VSTO programming.”

–Rufus Littlefield, software design engineer/tester, Microsoft Corporation

“This book will help Office .NET Developers optimize their work. It goes beyond providing an introduction to VSTO and the object models of Word, Excel, and Outlook. The overview of other technologies available for interacting with Office assist in analyzing how to best approach any Office project. In addition, the authors’ insights into the design of this RAD tool make it possible to get the most out of VSTO applications.”

–Cindy Meister, Microsoft MVP for VSTO, author of Word Programmierung, Das Handbuch

“This book is an in-depth, expert, and definitive guide to programming using Visual Studio Tools for Office 2007. It is a must-have book for anyone doing Office development.”

–Siew Moi Khor, programmer/writer, Microsoft Corporation

“We don’t buy technical books for light reading, we buy them as a resource for developing a solution. This book is an excellent resource for someone getting started with Smart Client development. For example, it is common to hear a comment along the lines of, ‘It is easy to manipulate the Task Pane in Office 2007 using VSTO 2008,’ but until you see something like the example at the start of Chapter 14, it is hard to put ‘easy’ into perspective.

“This is a thorough book that covers everything from calling Office applications from your application, to building applications that are Smart Documents. It allows the traditional Windows developer to really leverage the power of Office 2007.”

–Bill Sheldon, principal engineer, InterKnowlogy; MVP

“Eric Carter and Eric Lippert have been the driving force behind Office development and Visual Studio Tools for Office. The depth of their knowledge and understanding of VSTO and Office is evident in this book. Professional developers architecting enterprise solutions using VSTO 2008 and Office system 2007 now have a new weapon in their technical arsenal.”

–Paul Stubbs, program manager, Microsoft Corporation

“This book, also known as ‘The Bible of VSTO,’ has been rewritten for Office 2007 and I was delighted to read the sections on new VSTO features that were added in Visual Studio 2008. It explains how the VSTO team hid the plumbing and cumbersome coding tasks to allow you to be more productive and to just create excellent business applications. New or experienced in Office development, you will want to add this book to your library!”

–Maarten van Stam, Microsoft MVP, Visual Developer, VSTO, http://blogs.officezealot.com/maarten

“This book covers all of the ins and outs of programming with Visual Studio Tools for Office in a clear and concise way. Given the authors’ exhaustive experiences with this subject, you can’t get a more authoritative description of VSTO than this book!”

–Paul Vick, principal architect, Microsoft Corporation

Read More Show Less

Product Details

  • ISBN-13: 9780321533210
  • Publisher: Addison-Wesley
  • Publication date: 2/27/2009
  • Series: Microsoft .NET Development Series
  • Edition description: New Edition
  • Edition number: 2
  • Pages: 1120
  • Sales rank: 1,004,935
  • Product dimensions: 6.90 (w) x 9.20 (h) x 2.40 (d)

Meet the Author

Eric Carter is a development manager on the Visual Studio team at Microsoft. He helped invent, design, and implement many of the features that are in VSTO today. Previously at Microsoft he worked on Visual Studio for Applications, the Visual Studio Macros IDE, and Visual Basic for Applications for Office 2000 and Office 2003.

Eric Lippert’s primary focus during his twelve years at Microsoft has been on improving the lives of developers by designing and implementing useful programming languages and development tools. He has worked on the Windows Scripting family of technologies, Visual Studio Tools for Office, and, most recently, on the C# compiler team.

Read More Show Less

Read an Excerpt

PrefacePreface

In 2002 the first release of Visual Studio .NET and the .NET Framework was nearing completion. A few of us at Microsoft realized that Office programming was going to miss the .NET wave unless we did something about it.

What had come before was Visual Basic for Applications (VBA), a simple development environment integrated into all the Office applications. Each Office application had a rich object model that was accessed via a technology known as COM. Millions of developers identified themselves as “Office developers” and used VBA and the Office COM object models to do everything from automating repetitive tasks to creating complete business solutions that leveraged the rich features and user interface of Office. These developers realized that their users were spending their days in Office. By building solutions that ran inside Office, they not only made their users happy, but also were able to create solutions that did more and cost less by reusing functionality already available in the Office applications.

Unfortunately, because of some limitations of VBA, Office programming was starting to get a bad rap. Solutions developed in VBA by small workgroups or individuals would gain momentum, and a professional developer would have to take them over and start supporting them. To a professional developer, the VBA environment felt simple and limited, and of course, it enforced a single language: Visual Basic. VBA embedded code in every customized document, which made it hard to fix bugs and update solutions because a bug would get replicated in documents across the enterprise. Security weaknesses in the VBA model led to a rash of worms and macro viruses that made enterprises turn VBA off.

Visual Studio .NET and the .NET Framework provided a way to address all these problems. A huge opportunity existed not only to combine the richness of the new .NET Framework and developer tools with the powerful platform that Office has always provided for developers, but also to solve the problems that were plaguing VBA. The result of this realization was Visual Studio Tools for Office (VSTO).

The first version of VSTO was simple, but it accomplished the key goal of letting professional developers use the full power of Visual Studio .NET and the .NET Framework to put code behind Excel 2003 and Word 2003 documents and templates. It let professional developers develop Office solutions in Visual Basic and C#. It solved the problem of embedded code by linking a document to a .NET assembly instead of embedding it in the document. It also introduced a new security model that used .NET code-access security to prevent worms and macro viruses.

The second version of VSTO, known as VSTO 2005, was even more ambitious. It brought with it functionality never available to the Office developer before, such as data binding and data/view separation, design-time views of Excel and Word documents inside Visual Studio, rich support for Windows Forms controls in the document, the ability to create custom Office task panes, server-side programming support against Office—and that’s just scratching the surface. Although the primary target of VSTO is the professional developer, that does not mean that building an Office solution with VSTO is rocket science. VSTO makes it possible to create very rich applications with just a few lines of code.

The third version of VSTO, which this book focuses on, shipped as a core feature of Visual Studio 2008. It is sometimes said that it takes Microsoft three versions to get something right, and we truly feel that this version of VSTO has the most amazing support for Office programming that Microsoft has ever built. In VSTO, you can now build add-ins for all the major Office applications; you can build application-level custom task panes; you can customize the new Office Ribbon; you can modify Outlook’s UI using Forms Regions, and you can easily deploy everything you build using ClickOnce. The Office 2007 applications themselves are more extensible and provide many new programmability features.

If you’ve been reluctant to use VSTO because of the issues in previous versions—such as the difficulty of deployment, the nonsupport of VSTO in the Visual Studio Professional SKU, and the limited support for add-ins—we’re happy to tell you that these issues have been fixed in the third version of VSTO.

This book tries to put in one place all the information you need to succeed using VSTO to program against Word 2007, Excel 2007, and Outlook 2007. It introduces the Office 2007 object models and covers the most commonly used objects in those object models. In addition, this book helps you avoid some pitfalls that result from the COM origins of the Office object models. This book also provides necessary backround for developers using VSTO to customize Visio 2007, Publisher 2007, PowerPoint 2007, and InfoPath 2007. Although it doesn’t specifically focus on these applications, it teaches how to use the VSTO add-in model, how to create custom task panes and ribbons, and how to code against Office object models using C#.

This book also provides an insider view of all the rich features of VSTO. We participated in the design and implementation of many of these features; therefore, we can speak from the unique perspective of living and breathing VSTO for the past six years. Programming Office using VSTO is powerful and fun. We hope you enjoy using VSTO as much as we enjoyed writing about it and creating it.

Eric Carter
Eric Lippert
January 2009

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Table of Contents

Figures xxxi

Tables xlv

Foreword li

Preface lv

Acknowledgments lix

About the Authors lxi

Part I: An Introduction to VSTO 1

Chapter 1: An Introduction to Office Programming 3

Why Office Programming? 3

Office Business Applications 3

Office Object Models 7

Properties, Methods, and Events 14

The Office Primary Interop Assemblies (PIAs) 39

Conclusion 48

Chapter 2: Introduction to Office Solutions 51

The Three Basic Patterns of Office Solutions 51

Office Automation Executables 54

Office Add-Ins 69

Code Behind a Document 78

Conclusion 86

Part II: Office Programming in .NET 87

Chapter 3: Programming Excel 89

Ways to Customize Excel 89

Programming User-Defined Functions 98

Introduction to the Excel Object Model 108

Conclusion 112

Chapter 4: Working with Excel Events 115

Events in the Excel Object Model 115

Conclusion 162

Chapter 5: Working with Excel Objects 163

Working with the Application Object 163

Working with the Workbooks Collection 178

Working with the Workbook Object 181

Working with the Worksheets, Charts,

Working with Document Properties 192

Working with the Windows Collections 195

Working with the Window Object 199

Working with the Names Collection and Name Object 202

Working with the Worksheet Object 204

Working with the Range Object 219

Special Excel Issues 235

Conclusion 241

Chapter 6: Programming Word 243

Ways to Customize Word 243

Programming Research Services 249

Introduction to the Word Object Model 261

Conclusion 262

Chapter 7: Working with Word Events 267

Events in the Word Object Model 267

Events in Visual Studio Tools for Office 307

Conclusion 310

Chapter 8: Working with Word Objects 311

Working with the Application Object 311

Working with the Dialog Object 332

Working with Windows 338

Working with Templates 341

Working with Documents 343

Working with a Document 348

Working with the Range Object 369

Working with Bookmarks 392

Working with Tables 394

Working with Content Controls 396

Conclusion 403

Chapter 9: Programming Outlook 405

Ways to Customize Outlook 405

Introduction to the Outlook Object Model 419

Conclusion 422

Chapter 10: Working with Outlook Events 425

Events in the Outlook Object Model 425

Application-Level Events 427

Outlook Item Events 448

Other Events 470

Conclusion 473

Chapter 11: Working with Outlook Objects 475

Working with the Application Object 475

Working with the Explorers and Inspectors Collections 486

Working with the Explorer Object 488

Working with the Inspector Object 501

Working with the NameSpace Object 506

Working with the Folder Object 519

Working with the Items Collection 534

Properties and Methods Common to Outlook Items 548

Conclusion 569

Part III: Office Programming in VSTO 571

Chapter 12: The VSTO Programming Model 573

The VSTO Programming Model for Documents 573

VSTO Extensions to Word and Excel Document Objects 576

Dynamic Controls in the Document 584

Advanced Topic: Class Hookup and Cookies 591

Advanced Topic: Inspecting the Generated Code 594

VSTO Extensions to the Word and Excel Object Models 599

The VSTO Programming Model for Add-Ins 619

Using VSTO Document Features in Application-Level Add-Ins 621

Advanced Topic: Creating Worksheets Dynamically 624

Conclusion 625

Chapter 13: Using Windows Forms and WPF in VSTO 627

Introduction 627

Adding Windows Forms Controls to Your Document 634

Writing Code Behind a Control 641

The Windows Forms Control Hosting Architecture 643

Properties Merged from OLEObject or OLEControl 654

Adding Controls at Runtime 658

Using WPF Controls in the Document 669

Conclusion 671

Chapter 14: Working with Document-Level Actions Panes 673

Introduction to the Document Actions Task Pane 673

Working with the ActionsPane Control 680

Using WPF Controls in an Actions Pane 697

Conclusion 699

Chapter 15: Working with Application-Level Custom Task Panes 701

Introduction to the Application-Level Custom Task Panes 701

Working with Custom Task Panes 704

Custom Task Panes and Application Windows 710

Using WPF Controls in a Custom Task Pane 719

Conclusion 722

Chapter 16: Working with Outlook Form Regions 723

Introduction to Form Regions 723

Form Region Types and Custom Message Classes 743

Creating an Outlook Forms-Based Form Region 749

Outlook Form Region Programmability 765

Conclusion 774

Chapter 17: Working with the Ribbon in VSTO 777

Introduction to the Office Ribbon 777

Working with the Ribbon in the Ribbon Designer 800

Creating a Ribbon in an Excel Workbook Project 812

Creating a Ribbon in an Outlook Add-In Project 825

Advanced Ribbon Topics 836

Conclusion 850

Chapter 18: Working with Smart Tags in VSTO 851

Introduction to Smart Tags 851

Creating Document-Level Smart Tags with VSTO 855

Creating Application-Level Smart Tags 874

Conclusion 880

Chapter 19: VSTO Data Programming 881

Creating a Data-Bound Customized Spreadsheet with VSTO 882

Creating a Data-Bound Customized Word Document with VSTO 889

Datasets, Adapters, and Sources 891

Another Technique for Creating Data-Bound Documents 901

Caching Data in the Data Island 908

Advanced Topic: Using ICachedType 911

Advanced ADO.NET Data Binding: Looking Behind the Scenes 913

Binding-Related Extensions to Host Items and Host Controls 914

Using Data Binding and Dynamic Controls from an Application-Level Add-In 921

Conclusion 928

Chapter 20: Server Data Scenarios 929

Populating a Document with Data on the Server 929

Using ServerDocument and ASP.NET 931

A Handy Client-Side ServerDocument Utility 939

The ServerDocument Object Model 941

Conclusion 952

Chapter 21: ClickOnce Deployment 955

Introduction 955

Prerequisites 956

Deploying Add-Ins 958

Deploying Document Solutions 982

ClickOnce Security 995

Other Deployment Scenarios 1009

Advanced Topic: Editing Manifests Using Mage 1010

Conclusion 1015

Bibliography 1017

Index 1019

Read More Show Less

Preface

Preface

In 2002 the first release of Visual Studio .NET and the .NET Framework was nearing completion. A few of us at Microsoft realized that Office programming was going to miss the .NET wave unless we did something about it.

What had come before was Visual Basic for Applications (VBA), a simple development environment integrated into all the Office applications. Each Office application had a rich object model that was accessed via a technology known as COM. Millions of developers identified themselves as “Office developers” and used VBA and the Office COM object models to do everything from automating repetitive tasks to creating complete business solutions that leveraged the rich features and user interface of Office. These developers realized that their users were spending their days in Office. By building solutions that ran inside Office, they not only made their users happy, but also were able to create solutions that did more and cost less by reusing functionality already available in the Office applications.

Unfortunately, because of some limitations of VBA, Office programming was starting to get a bad rap. Solutions developed in VBA by small workgroups or individuals would gain momentum, and a professional developer would have to take them over and start supporting them. To a professional developer, the VBA environment felt simple and limited, and of course, it enforced a single language: Visual Basic. VBA embedded code in every customized document, which made it hard to fix bugs and update solutions because a bug would get replicated in documents across the enterprise. Security weaknesses in the VBA model led to a rash of worms and macro viruses that made enterprises turn VBA off.

Visual Studio .NET and the .NET Framework provided a way to address all these problems. A huge opportunity existed not only to combine the richness of the new .NET Framework and developer tools with the powerful platform that Office has always provided for developers, but also to solve the problems that were plaguing VBA. The result of this realization was Visual Studio Tools for Office (VSTO).

The first version of VSTO was simple, but it accomplished the key goal of letting professional developers use the full power of Visual Studio .NET and the .NET Framework to put code behind Excel 2003 and Word 2003 documents and templates. It let professional developers develop Office solutions in Visual Basic and C#. It solved the problem of embedded code by linking a document to a .NET assembly instead of embedding it in the document. It also introduced a new security model that used .NET code-access security to prevent worms and macro viruses.

The second version of VSTO, known as VSTO 2005, was even more ambitious. It brought with it functionality never available to the Office developer before, such as data binding and data/view separation, design-time views of Excel and Word documents inside Visual Studio, rich support for Windows Forms controls in the document, the ability to create custom Office task panes, server-side programming support against Office—and that’s just scratching the surface. Although the primary target of VSTO is the professional developer, that does not mean that building an Office solution with VSTO is rocket science. VSTO makes it possible to create very rich applications with just a few lines of code.

The third version of VSTO, which this book focuses on, shipped as a core feature of Visual Studio 2008. It is sometimes said that it takes Microsoft three versions to get something right, and we truly feel that this version of VSTO has the most amazing support for Office programming that Microsoft has ever built. In VSTO, you can now build add-ins for all the major Office applications; you can build application-level custom task panes; you can customize the new Office Ribbon; you can modify Outlook’s UI using Forms Regions, and you can easily deploy everything you build using ClickOnce. The Office 2007 applications themselves are more extensible and provide many new programmability features.

If you’ve been reluctant to use VSTO because of the issues in previous versions—such as the difficulty of deployment, the nonsupport of VSTO in the Visual Studio Professional SKU, and the limited support for add-ins—we’re happy to tell you that these issues have been fixed in the third version of VSTO.

This book tries to put in one place all the information you need to succeed using VSTO to program against Word 2007, Excel 2007, and Outlook 2007. It introduces the Office 2007 object models and covers the most commonly used objects in those object models. In addition, this book helps you avoid some pitfalls that result from the COM origins of the Office object models. This book also provides necessary backround for developers using VSTO to customize Visio 2007, Publisher 2007, PowerPoint 2007, and InfoPath 2007. Although it doesn’t specifically focus on these applications, it teaches how to use the VSTO add-in model, how to create custom task panes and ribbons, and how to code against Office object models using C#.

This book also provides an insider view of all the rich features of VSTO. We participated in the design and implementation of many of these features; therefore, we can speak from the unique perspective of living and breathing VSTO for the past six years. Programming Office using VSTO is powerful and fun. We hope you enjoy using VSTO as much as we enjoyed writing about it and creating it.

Eric Carter
Eric Lippert
January 2009

© Copyright Pearson Education. All rights reserved.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted August 11, 2011

    No text was provided for this review.

Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)