15
Bill Sempf Peter Jausovec Learn to: Develop productivity applications using Visual Basic® 2010 Build dynamic applications in Excel ® , Word, and Outlook® Create effective user interfaces Integrate VSTO Office Applications with Microsoft SharePoint Foundation VSTO Making Everything Easier! VSTO

VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Embed Size (px)

Citation preview

Page 1: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Bill SempfPeter Jausovec

Learn to:• Develop productivity applications using

Visual Basic® 2010

• Build dynamic applications in Excel®, Word, and Outlook®

• Create effective user interfaces

• Integrate VSTO Office Applications with Microsoft SharePoint Foundation

VSTOMaking Everything Easier!™

Visit the companion Web site at www.dummies.com/go/vstofd to find all the code examples used in this book, ready to use for building your own applications

Open the book and find:

• What version of VSTO works with what version of Office

• Secrets of smart documents

• How to create Excel add-ins

• Projects you can create for Microsoft Project

• What VSTO can do with PowerPoint and Visio

• Important security stuff to consider

• How to work with SharePoint Foundation and VSTO

• Ten cool ideas for VSTO projects

Bill Sempf is a solutions architect specializing in Internet technologies. He is an established writer and speaker on a range of technology topics. Peter Jausovec is a software development engineer who works on VSTO and SharePoint testing at Microsoft.

$29.99 US / $35.99 CN / £21.99UK

ISBN 978-0-470-04647-0

Microsoft Office Programming

Go to Dummies.com®

for videos, step-by-step examples, how-to articles, or to shop!

Install the VSTO toolset and start building a smarter OfficeWith VSTO, aka Visual Studio Tools for Office, you can customize Office to your heart’s content. From simple add-ins to full-scale customized documents, you can develop ways to boost functionality, create documents that “think,” and get Office applications talking to each other. Learn how to get going with VSTO and build the Office of your dreams!

• Make Office better — add functionality, leverage existing functionality, integrate documents with other apps and databases, and tie your Office applications together with SharePoint

• Get the Word — create custom Word documents for specific, repetitive uses

• Enhance your Outlook — create add-ins that help you manage your schedule and e-mail more efficiently

• Make the Ribbon work for you — modify and customize the Ribbon interface and even create a Ribbon for your project

• Serve it up — deploy your creations with ClickOnce, troubleshoot them, and keep them up to date

VSTOSempf

Jausovec

spine=.672”

Page 2: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

spine=.672”

Mobile Apps

There’s a Dummies App for This and ThatWith more than 200 million books in print and over 1,600 unique titles, Dummies is a global leader in how-to information. Now you can get the same great Dummies information in an App. With topics such as Wine, Spanish, Digital Photography, Certification, and more, you’ll have instant access to the topics you need to know in a format you can trust.

To get information on all our Dummies apps, visit the following:

www.Dummies.com/go/mobile from your computer.

www.Dummies.com/go/iphone/apps from your phone.

Start with FREE Cheat SheetsCheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff!

Get Smart at Dummies.com Dummies.com makes your life easier with 1,000s of answers on everything from removing wallpaper to using the latest version of Windows.

Check out our • Videos • Illustrated Articles • Step-by-Step Instructions

Plus, each month you can win valuable prizes by entering our Dummies.com sweepstakes. *

Want a weekly dose of Dummies? Sign up for Newsletters on • Digital Photography • Microsoft Windows & Office • Personal Finance & Investing • Health & Wellness • Computing, iPods & Cell Phones • eBay • Internet • Food, Home & Garden

Find out “HOW” at Dummies.com

*Sweepstakes not currently available in all countries; visit Dummies.com for official rules.

Get More and Do More at Dummies.com®

To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/vstofd

Page 3: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

VSTOFOR

DUMmIES‰

01_046470-ffirs.indd i01_046470-ffirs.indd i 9/15/10 1:52 PM9/15/10 1:52 PM

Page 4: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

01_046470-ffirs.indd ii01_046470-ffirs.indd ii 9/15/10 1:52 PM9/15/10 1:52 PM

Page 5: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

by Bill Sempf and Peter Jausovec

VSTOFOR

DUMmIES‰

01_046470-ffirs.indd iii01_046470-ffirs.indd iii 9/15/10 1:52 PM9/15/10 1:52 PM

Page 6: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

VSTO For Dummies®

Published byWiley Publishing, Inc.111 River StreetHoboken, NJ 07030-5774

www.wiley.com

Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

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 permit-ted 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 Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates in the United States and other countries, and may not be used without written permission. 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.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH-OUT 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 PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZA-TION 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 U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

For technical support, please visit www.wiley.com/techsupport.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2007926401

ISBN: 978-0-470-04647-0

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

01_046470-ffirs.indd iv01_046470-ffirs.indd iv 9/15/10 1:52 PM9/15/10 1:52 PM

Page 7: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

About the AuthorsBill Sempf: Bill started playing with computers in 1979 and hasn’t looked back. In 1985, he was helping his father (also Bill) manage Apple IIe systems at the local library. Since then, Bill has built applications for the likes of Lucent Technologies, Bank One, Nationwide Insurance, and Sears, Roebuck and Co. He is the author of C# 2010 All-in-One For Dummies and Visual Basic 2008 For Dummies; a coauthor of Effective Visual Studio.NET, Professional ASP.NET Web Services and Professional VB.NET; a frequent contributor to MSDN, Builder.com, Hardcore Web Services, Cloud Computing Journal, Inside Web Development Journal and Intranet Journal; and an invited speaker for the ACM and IEEE, nPlus1, DevEssentials, the International XML Web Services Expo, and the Association of Information Technology Professionals. Bill is a graduate of The Ohio State University with a Bachelor’s of Science in Business Administration, Microsoft Certifi ed Professional, Certifi ed Internet Business Strategist and Certifi ed Internet Webmaster. His company is Products Of Innovative New Technology (usually called POINT), and you can reach Bill at [email protected].

Peter Jausovec: Peter has worked with Visual Studio Tools for Offi ce (VSTO) since the fi rst version. He is currently employed at Microsoft where he helped test and design the Microsoft Visual Studio 2010 SharePoint developer tools, focusing especially on SharePoint Workfl ows.

DedicationFrom Bill: To my wife Gabrielle and my son Adam. They put up with many a movie date with Daddy illuminated by his laptop screen.

From Peter: To my wife Nives.

01_046470-ffirs.indd v01_046470-ffirs.indd v 9/15/10 1:52 PM9/15/10 1:52 PM

Page 8: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

01_046470-ffirs.indd vi01_046470-ffirs.indd vi 9/15/10 1:52 PM9/15/10 1:52 PM

Page 9: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Authors’ AcknowledgmentsThis book has a long story behind it, which Bill will be glad to tell for the price of a beer at any of the community events he frequents. That story demands an acknowledgement of two particular groups — the developer community and Wiley.

When Bill came up with this title concept way back in 2006, he leaned heavily on the developer community for ideas and structure. This leaning turned into a true partnership, when Peter joined the fray as a co-author in 2008.

Then just a student, Peter would end up becoming a force in the develop-ment of this book, crafting the message presented and writing half the text. He then worked to update the older chapters to appropriately encompass VSTO 4.0 after he joined Microsoft’s VSTO development team. His work, and the community that supports the creation of vital technologists like him, deserve everyone’s recognition, support, and participation.

In that same vein, Eric Carter’s early support from the technical perspective was very important to the book. Maarten van Stam’s expertise in tech review has been fantastic, too. Both of those gentlemen have a deep and broad understanding of the technical issues of VSTO, and their help fi rming up the ideas presented was truly a cornerstone of the book.

Wiley, the company that publishes the For Dummies series, deserves a hat tip for sticking with this book. Many people, especially Katie Feltman and Kelly Ewing, allowed this to title draw out long beyond the timeline for most books while we waited for the technology to settle. We believe it was worth the wait and hope you do, too!

01_046470-ffirs.indd vii01_046470-ffirs.indd vii 9/15/10 1:52 PM9/15/10 1:52 PM

Page 10: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Publisher’s Acknowledgments

We’re proud of this book; please send us your comments at http://dummies.custhelp.com. For other comments, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.

Some of the people who helped bring this book to market include the following:

Acquisitions and Editorial

Project Editor: Kelly Ewing

Acquisitions Editor: Katie Feltman

Technical Editor: Maarten van Stam

Editorial Manager: Jodi Jensen

Editorial Assistant: Amanda Graham

Sr. Editorial Assistant: Cherie Case

Cartoons: Rich Tennant (www.the5thwave.com)

Composition Services

Project Coordinator: Patrick Redmond

Layout and Graphics: Carl Byers

Proofreaders: The Well-Chosen Word, Lauren Mandelbaum

Indexer: Christine Karpeles

Publishing and Editorial for Technology Dummies

Richard Swadley, Vice President and Executive Group Publisher

Andy Cummings, Vice President and Publisher

Mary Bednarek, Executive Acquisitions Director

Mary C. Corder, Editorial Director

Publishing for Consumer Dummies

Diane Graves Steele, Vice President and Publisher

Composition Services

Debbie Stailey, Director of Composition Services

01_046470-ffirs.indd viii01_046470-ffirs.indd viii 9/15/10 1:52 PM9/15/10 1:52 PM

Page 11: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Contents at a GlanceIntroduction ................................................................ 1

Part I: Introducing VSTO .............................................. 5Chapter 1: Getting Started with VSTO ............................................................................ 7Chapter 2: Building an Add-in ........................................................................................ 21Chapter 3: Making Your Documents Smart .................................................................. 35Chapter 4: Designing for VSTO ....................................................................................... 49

Part II: VSTO Construction .......................................... 61Chapter 5: Building Word Add-Ins ................................................................................. 63Chapter 6: Customizing Word Documents ................................................................... 83Chapter 7: Building an Excel Add-In ............................................................................ 109Chapter 8: Putting Customers into Excel .................................................................... 119Chapter 9: Presenting PowerPoint............................................................................... 141Chapter 10: Building an Outlook Job Jar Add-in ........................................................ 159Chapter 11: Creating a Project Project........................................................................ 177Chapter 12: Developing for Visio ................................................................................. 185

Part III: Developing for SharePoint ........................... 201Chapter 13: Working with SharePoint ......................................................................... 203Chapter 14: Building SharePoint Workfl ows .............................................................. 221Chapter 15: Building SharePoint Lists and Libraries ................................................ 235

Part IV: Finishing Up ............................................... 261Chapter 16: Security ...................................................................................................... 263Chapter 17: Deploying VSTO Solutions ....................................................................... 269

Part V: The Part of Tens ........................................... 281Chapter 18: Ten Reasons to Ditch Web Programming .............................................. 283Chapter 19: Ten Cool Ideas and Resources for Your Next VSTO Project ............... 289Chapter 20: Ten Ways to Integrate SharePoint .......................................................... 299

Index ...................................................................... 305

02_046470-ftoc.indd ix02_046470-ftoc.indd ix 9/15/10 1:14 PM9/15/10 1:14 PM

Page 12: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

02_046470-ftoc.indd x02_046470-ftoc.indd x 9/15/10 1:14 PM9/15/10 1:14 PM

Page 13: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

Table of Contents

Introduction ................................................................. 1About This Book .............................................................................................. 1Conventions Used in This Book ..................................................................... 2What You’re Not to Read ................................................................................ 2Foolish Assumptions ....................................................................................... 2How This Book Is Organized .......................................................................... 2

Part I: Introducing VSTO ....................................................................... 3Part II: VSTO Construction ................................................................... 3Part III: Developing for SharePoint ...................................................... 3Part IV: Finishing Up .............................................................................. 3Part V: The Part of Tens ........................................................................ 3

Icons Used in This Book ................................................................................. 4Where to Go from Here ................................................................................... 4

Part I: Introducing VSTO ............................................... 5

Chapter 1: Getting Started with VSTO . . . . . . . . . . . . . . . . . . . . . . . . . . . .7

Harnessing the Power of VSTO ...................................................................... 7Talking about add-ins and Customized Documents .......................... 8Solving your problems with four VSTO features ............................... 9

Exploring the Different Versions of VSTO .................................................. 11Visual Studio 2003 and 2005 ............................................................... 12VSTO 2005 SE ........................................................................................ 12VSTO 3.0 ................................................................................................ 12Visual Studio 2010 and VSTO 4.0 ....................................................... 13Offi ce 2003............................................................................................. 13Offi ce 2007............................................................................................. 14Earlier versions .................................................................................... 15

Installing VSTO ............................................................................................... 15Requirements ....................................................................................... 15Supporting software ............................................................................ 16

Using VSTO in Visual Studio ........................................................................ 17Using VSTO projects ............................................................................ 17Working toward a fi nished product................................................... 18Starting with the end in mind ............................................................. 19

02_046470-ftoc.indd xi02_046470-ftoc.indd xi 9/15/10 1:14 PM9/15/10 1:14 PM

Page 14: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

VSTO For Dummies xiiChapter 2: Building an Add-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21

What’s an Add-In, Anyway? .......................................................................... 21Making a New Project .................................................................................... 22Making the Add-In Do Amazing Things ....................................................... 25

Adding a user interface to your add-in ............................................. 27Putting some data in that add-in ........................................................ 30

Making the Add-In Work ............................................................................... 31Seeing Your Add-In in Action ....................................................................... 32

Chapter 3: Making Your Documents Smart . . . . . . . . . . . . . . . . . . . . . . .35

What Is a Smart Document, Anyway? ......................................................... 35Taking a Peek at a Quick Example ............................................................... 37

Creating a new project ........................................................................ 37Adding basic customizations ............................................................. 40Getting a little more advanced ........................................................... 42

Seeing Your Work in Action ......................................................................... 44

Chapter 4: Designing for VSTO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49

Meeting the Growing Requirements of Users ............................................ 49Compacting the most work into the least time ................................ 50Using pre-existing functionality ......................................................... 51

Planning for a Project .................................................................................... 52Scoping out the system ....................................................................... 53Gathering requirements ...................................................................... 54Designing the feature set .................................................................... 54

Figuring Out What VSTO Can Do for You ................................................... 54Individual applications ........................................................................ 55Working together ................................................................................. 56

Designing Powerful Applications Quickly .................................................. 56Defi ning your scope ............................................................................. 56The power of Smart Clients ................................................................ 57Using powerful libraries ...................................................................... 57Leveraging a good IDE ......................................................................... 57Understanding the limitations ........................................................... 58

Getting Help from VSTO ............................................................................... 58A platform familiar to users ................................................................ 58Library of work ..................................................................................... 59Existing functionality ........................................................................... 59

Part II: VSTO Construction .......................................... 61

Chapter 5: Building Word Add-Ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .63

Getting Used to the Ribbon .......................................................................... 63Customizing the Ribbon with Add-Ins ........................................................ 64

Creating an Offi ce add-in project with a Ribbon .............................. 64Adding a Ribbon to your project ....................................................... 65

02_046470-ftoc.indd xii02_046470-ftoc.indd xii 9/15/10 1:14 PM9/15/10 1:14 PM

Page 15: VSTO For Dummies - Buch.de - Bücher versandkostenfrei - … … ·  · 2015-09-09. ... helped test and design the Microsoft Visual Studio 2010 SharePoint developer ... Peter would

xiii Table of Contents

Building Custom Task Panes ........................................................................ 67Adding controls to the Task pane ..................................................... 69Adding code to the Task pane............................................................ 70Adding functionality to the Task pane .............................................. 71

Handling Events in Add-Ins .......................................................................... 73Creating an event handler .................................................................. 74Accessing global document information .......................................... 74Creating your own events ................................................................... 75Taking an interface to the bank ......................................................... 76Giving the bank some class ................................................................ 78Calling up the pane from Word .......................................................... 79

Putting the Account Panel All Together ..................................................... 80Adding a Ribbon control ..................................................................... 80Making the Task pane appear and disappear .................................. 81

Chapter 6: Customizing Word Documents . . . . . . . . . . . . . . . . . . . . . . . .83

Exploring the Word Object Model ............................................................... 83The Application object ........................................................................ 85The Document object .......................................................................... 85The Range and Selection objects ....................................................... 87The Bookmark object .......................................................................... 90

Working with Tables ..................................................................................... 90Designing a Smart Word Template .............................................................. 91

The template! It’s alive, alive! ............................................................. 92Coding up a salesperson ..................................................................... 94Showing you the data .......................................................................... 97

Programming the Ribbon ........................................................................... 100Browsing the Ribbon controls ......................................................... 101Adding a Ribbon to marketing letters ............................................. 103Seeing your work in action ............................................................... 106

Chapter 7: Building an Excel Add-In. . . . . . . . . . . . . . . . . . . . . . . . . . . .109

Creating a New Project ............................................................................... 109Designing a Dialog Box ................................................................................ 110

Using the dialog box in your add-in ................................................. 113Seeing your work in action ............................................................... 115

Chapter 8: Putting Customers into Excel . . . . . . . . . . . . . . . . . . . . . . . .119

Customizing Excel Workbooks .................................................................. 119Getting to core Excel functions ........................................................ 120Creating invoices in Excel ................................................................. 121

Working with the Action pane ................................................................... 125Working with the Custom Task Pane ........................................................ 126

Adding real data ................................................................................. 126Binding VSTO controls ...................................................................... 127

02_046470-ftoc.indd xiii02_046470-ftoc.indd xiii 9/15/10 1:14 PM9/15/10 1:14 PM