Microsoft® Outlook 2007 Programming: Jumpstart for Administrators and Power Users This page intentionally left blank Microsoft® Outlook 2007 Programming: Jumpstart for Administrators and Power Users Sue Mosher Amsterdam • Boston • Heidelberg • London • New York • Oxford Paris • San Diego • San Francisco • Singapore • Sydney • Tokyo Digital Press is an imprint of Elsevier Digital Press is an imprint of Elsevier 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA Linacre House, Jordan Hill, Oxford OX2 8DP, UK Copyright © 2007, Elsevier Inc. All rights reserved. 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, or otherwise, without the prior written permission of the publisher. Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: [email protected]. You may also complete your request online via the Elsevier homepage (http://elsevier.com), by selecting “Support & Contact” then “Copyright and Permission” and then “Obtaining Permissions.” Recognizing the importance of preserving what has been written, Elsevier prints its books on acid- free paper whenever possible. Library of Congress Cataloging-in-Publication Data Application submitted British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN: 978-1-55558-346-0 For information on all Digital Press publications visit our Web site at www.books.elsevier.com Printed in the United States of America 07 08 09 10 10 9 8 7 6 5 4 3 2 1 Contents Introduction xi Acknowledgments xiii 1 What You Can Do with Outlook 2007 1 1.1 Why program with Outlook? 2 1.2 Outlook programming tools 2 1.3 How to start 9 1.4 Key Outlook programming components 11 1.5 Showing developer commands 11 1.6 Summary 13 Part I Basic Outlook VBA Design 2 The VBA Design Environment 15 2.1 VBA: The basics 15 2.2 VBA windows 18 2.3 Getting help in VBA 24 2.4 Working with VBA projects 26 2.5 Summary 29 3 Building Your First VBA Form 31 3.1 Understanding Outlook birthdays and anniversaries 31 3.2 Step 1: What controls do you need? 32 3.3 Step 2: Create the form 33 3.4 Step 3: Add user input controls 36 3.5 Step 4: Add command buttons 38 v vi Contents 3.6 Step 5: Plan the next development stage 45 3.7 More on VBA form controls 45 3.8 Summary 55 Part II Basic Outlook Form Design 4 Introducing Outlook Forms 57 4.1 Understanding the two types of custom forms 57 4.2 Starting the forms designer 59 4.3 The six standard Outlook forms 60 4.4 When to use which form 74 4.5 Working in the forms designer 76 4.6 Saving forms and ending a design session 78 4.7 Creating your first custom contact form 81 4.8 Summary 94 5 Introducing Form Regions 95 5.1 Understanding form regions 95 5.2 Controls for form regions 97 5.3 Creating your first form region 100 5.4 Registering and deploying form regions 103 5.5 Limitations of form regions 110 5.6 Other ideas for form regions 110 5.7 Summary 111 6 Extending Form Design with Fields and Controls 113 6.1 Understanding fields versus controls 113 6.2 Creating user-defined fields 114 6.3 Adding and removing fields on Outlook forms 122 6.4 Using form controls 128 6.5 Laying out compose and read pages 137 6.6 Summary 139 Part III Writing VBA and VBScript Code 7 Outlook Code Basics 141 7.1 Understanding when VBA code runs 141 7.2 Writing VBA code 152 Contents vii 7.3 Writing VBScript code for Outlook forms 159 7.4 Referring to Outlook item properties 168 7.5 Writing other Outlook automation code 171 7.6 Summary 175 8 Code Grammar 101 177 8.1 Option Explicit 177 8.2 Declaring variables and constants 179 8.3 Writing procedures 188 8.4 Working with expressions and functions 198 8.5 Working with strings 200 8.6 Working with dates and times 206 8.7 Using arrays, dictionaries, and the Split() and Join() functions 216 8.8 Controlling program flow 222 8.9 Providing feedback 234 8.10 Getting user input 240 8.11 Working with files and other objects 249 8.12 Summary 258 9 Handling Errors, Testing, and Debugging 261 9.1 Understanding errors 261 9.2 Testing and debugging in VBA 269 9.3 Debugging Outlook form VBScript code 277 9.4 Summary 287 Part IV Fundamental Outlook Coding Techniques 10 Outlook Programming Basics 289 10.1 Introducing the Outlook object model 289 10.2 Outlook object and collection code techniques 295 10.3 Understanding Outlook security 302 10.4 Summary 312 11 Responding to Outlook Events in VBA 313 11.1 Application object events 314 11.2 Writing handlers for other object events 329 11.3 Explorers and Explorer events 333 viii Contents 11.4 Inspectors and Inspector events 338 11.5 Folders, Folder, and Items events 343 11.6 Processing incoming mail 347 11.7 Using the Application.Reminder and Reminders events 356 11.8 Summary 369 12 Coding Key Custom Form Scenarios 371 12.1 Working with Outlook item events 371 12.2 Responding to user input on forms 377 12.3 Handling form and control state issues 391 12.4 Summary 400 13 Working with Stores, Explorers, and Folders 401 13.1 Information store concepts 401 13.2 Information store techniques 403 13.3 Working with Explorers 410 13.4 Accessing folders 412 13.5 Working with folders 434 13.6 Summary 442 14 Using PropertyAccessor and StorageItem 445 14.1 Using the PropertyAccessor object 446 14.2 Using the StorageItem object 458 14.3 Summary 462 15 Working with Inspectors and Items 463 15.1 Working with Inspectors 464 15.2 Creating items 467 15.3 Accessing items 474 15.4 Using the Table object 484 15.5 Using Item methods 492 15.6 Summary 500 16 Searching for Outlook Items 501 16.1 Introduction to Outlook search methods 501 16.2 Building search strings 503 Contents ix 16.3 Using Items.Find and Items.Restrict 521 16.4 Using Table search techniques 525 16.5 Using Explorer.Search 527 16.6 Using Application.AdvancedSearch 530 16.7 Summary 541 17 Working with Item Bodies 543 17.1 Basic item body techniques 543 17.2 Parsing text from a message body 545 17.3 Adding text to an item 547 17.4 Creating a formatted message 551 17.5 Using WordEditor 554 17.6 Working with Outlook signatures 563 17.7 Summary 568 18 Working with Recipients and Address Lists 569 18.1 Key recipient and address list objects 570 18.2 Understanding address lists 571 18.3 Working with item recipients 577 18.4 Reading Recipient and AddressEntry information 584 18.5 Reading free/busy information 588 18.6 Showing the Select Names dialog 594 18.7 Summary 601 19 Working with Attachments 603 19.1 Understanding Outlook attachments 603 19.2 Adding attachments to Outlook items 606 19.3 Working with attachments on existing items 608 19.4 Summary 618 20 Common Item Techniques 619 20.1 Using custom message forms 620 20.2 Working with voting buttons and other custom actions 626 20.3 Sending a message with a specific account 637 20.4 Creating a meeting request 639 20.5 Assigning a task 641
Description: