Mastering VBA for Microsoft Office 2013

Book description

A unique, comprehensive guide to creating custom apps with VBA

Automating computing tasks to increase productivity is a goal for businesses of all sizes. Visual Basic for Applications (VBA) is a version of Visual Basic designed to be easily understandable for novice programmers, but still powerful enough for IT professionals who need to create specialized business applications. With this invaluable book, you'll learn how to extend the capabilities of Office 2013 applications with VBA programming and use it for writing macros, automating Office applications, and creating custom applications in Word, Excel, PowerPoint, Outlook, and Access.

  • Covers the basics of VBA in clear, systematic tutorials and includes intermediate and advanced content for experienced VB developers

  • Explores recording macros and getting started with VBA; learning how to work with VBA; using loops and functions; using message boxes, input boxes, and dialog boxes; creating effective code; XML-based files, ActiveX, the developer tab, content controls, add-ins, embedded macros, and security

  • Anchors the content with solid, real-world projects in Word, Excel, Outlook, PowerPoint, and Access

  • Covering VBA for the entire suite of Office 2013 applications, Mastering VBA for Microsoft Office 2013 is mandatory reading.

    Table of contents

    1. Cover Page
    2. Title Page
    3. Copyright
    4. Wiley
    5. Dedication
    6. Acknowledgments
    7. About the Author
    8. Contents at a Glance
    9. Contents
    10. Introduction
      1. Where to Get This Book's Example Code
      2. If You Have Questions
      3. What Can I Do with VBA?
      4. What's in This Book?
      5. How Should I Use This Book?
      6. Is This Book Suitable for Me?
      7. Conventions Used in This Book
      8. The Mastering Series
      9. For More Information
    11. Part 1: Recording Macros and Getting Started with VBA
      1. Chapter 1: Recording and Running Macros in the Office Applications
        1. What Is VBA and What Can You Do with It?
        2. Understanding Macro Basics
        3. Recording a Macro
        4. Running a Macro
        5. Recording a Sample Word Macro
        6. Recording a Sample Excel Macro
        7. Specifying How to Trigger an Existing Macro
        8. Deleting a Macro
        9. The Bottom Line
      2. Chapter 2: Getting Started with the Visual Basic Editor
        1. Opening the Visual Basic Editor
        2. Using the Visual Basic Editor's Main Windows
        3. Setting Properties for a Project
        4. Customizing the Visual Basic Editor
        5. The Bottom Line
      3. Chapter 3: Editing Recorded Macros
        1. Testing a Macro in the Visual Basic Editor
        2. Editing the Word Macro
        3. Editing the Excel Macro
        4. Editing a PowerPoint Macro
        5. The Bottom Line
      4. Chapter 4: Creating Code from Scratch in the Visual Basic Editor
        1. Setting Up the Visual Basic Editor for Creating the Procedures
        2. Creating a Procedure for Word
        3. Creating a Procedure for Excel
        4. Creating a Procedure for PowerPoint
        5. Creating a Procedure for Access
        6. The Bottom Line
    12. Part 2: Learning How to Work with VBA
      1. Chapter 5: Understanding the Essentials of VBA Syntax
        1. Getting Ready
        2. Procedures
        3. Statements
        4. Keywords
        5. Expressions
        6. Operators
        7. Variables
        8. Constants
        9. Arguments
        10. Objects
        11. Collections
        12. Properties
        13. Methods
        14. Events
        15. The Bottom Line
      2. Chapter 6: Working with Variables, Constants, and Enumerations
        1. Working with Variables
        2. Working with Constants
        3. Working with Enumerations
        4. The Bottom Line
      3. Chapter 7: Using Array Variables
        1. What Is an Array?
        2. Declaring an Array
        3. Storing Values in an Array
        4. Multidimensional Arrays
        5. Declaring a Dynamic Array
        6. Redimensioning an Array
        7. Returning Information from an Array
        8. Erasing an Array
        9. Finding Out Whether a Variable Is an Array
        10. Finding the Bounds of an Array
        11. Sorting an Array
        12. Searching through an Array
        13. The Bottom Line
      4. Chapter 8: Finding the Objects, Methods, and Properties You Need
        1. What Is an Object?
        2. Working with Collections
        3. Finding the Objects You Need
        4. Using Object Variables to Represent Objects
        5. Team Programming and OOP
        6. The Bottom Line
    13. Part 3: Making Decisions and Using Loops and Functions
      1. Chapter 9: Using Built-in Functions
        1. What Is a Function?
        2. Using Functions
        3. Using Functions to Convert Data
        4. Using Functions to Manipulate Strings
        5. Using VBA's Mathematical Functions
        6. Using VBA's Date and Time Functions
        7. Using File-Management Functions
        8. The Bottom Line
      2. Chapter 10: Creating Your Own Functions
        1. Components of a Function
        2. Creating a Function
        3. Examples of Functions for Any VBA-Enabled Office Application
        4. Creating a Function for Word
        5. Creating a Function for Excel
        6. Creating a Function for PowerPoint
        7. Creating a Function for Access
        8. The Bottom Line
      3. Chapter 11: Making Decisions in Your Code
        1. How Do You Compare Things in VBA?
        2. Testing Multiple Conditions by Using Logical Operators
        3. Select Case Blocks
        4. The Bottom Line
      4. Chapter 12: Using Loops to Repeat Actions
        1. When Should You Use a Loop?
        2. Understanding the Basics of Loops
        3. Using For…loops for Fixed Repetitions
        4. Using Do… Loops for Variable Numbers of Repetitions
        5. While… Wend Loops
        6. Nesting Loops
        7. Avoiding Infinite Loops
        8. The Bottom Line
    14. Part 4: Using Message Boxes, Input Boxes, and Dialog Boxes
      1. Chapter 13: Getting User Input with Message Boxes and Input Boxes
        1. Opening a Procedure to Work On
        2. Displaying Status-Bar Messages in Word and Excel
        3. Message Boxes
        4. Input Boxes
        5. Forms: When Message Boxes and Input Boxes Won't Suffice
        6. The Bottom Line
      2. Chapter 14: Creating Simple Custom Dialog Boxes
        1. When Should You Use a Custom Dialog Box?
        2. Creating a Custom Dialog Box
        3. Linking a Form to a Procedure
        4. Retrieving the User's Choices from a Dialog Box
        5. Examples of Connecting Forms to Procedures
        6. Using an Application's Built-in Dialog Boxes from VBA
        7. The Bottom Line
      3. Chapter 15: Creating Complex Forms
        1. Creating and Working with Complex Dialog Boxes
        2. Using Events to Control Forms
        3. The Bottom Line
    15. Part 5: Creating Effective Code
      1. Chapter 16: Building Modular Code and Using Classes
        1. Creating Modular Code
        2. Creating and Using Classes
        3. The Bottom Line
      2. Chapter 17: Debugging Your Code and Handling Errors
        1. Principles of Debugging
        2. The Different Types of Errors
        3. VBA's Debugging Tools
        4. Dealing with Infinite Loops
        5. Dealing with Runtime Errors
        6. Suppressing Alerts
        7. Handling User Interrupts in Word, Excel, and Project
        8. Documenting Your Code
        9. The Bottom Line
      3. Chapter 18: Building Well-Behaved Code
        1. What Is a Well-Behaved Procedure?
        2. Retaining or Restoring the User Environment
        3. Leaving the User in the Best Position to Continue Working
        4. Keeping the User Informed during the Procedure
        5. Making Sure a Procedure Is Running under Suitable Conditions
        6. Cleaning Up after a Procedure
        7. The Bottom Line
      4. Chapter 19: Securing Your Code with VBA's Security Features
        1. Understanding How VBA Implements Security
        2. Signing Your Macro Projects with Digital Signatures
        3. Choosing a Suitable Level of Security
        4. Locking Your Code
        5. The Bottom Line
    16. Part 6: Programming the Office Applications
      1. Chapter 20: Understanding the Word Object Model and Key Objects
        1. Examining the Word Object Model
        2. Working with the Documents Collection and the Document Object
        3. Working with the Selection Object
        4. Creating and Using Ranges
        5. Manipulating Options
        6. The Bottom Line
      2. Chapter 21: Working with Widely Used Objects in Word
        1. Using Find and Replace via VBA
        2. Working with Headers, Footers, and Page Numbers
        3. Working with Sections, Page Setup, Windows, and Views
        4. Working with Tables
        5. The Bottom Line
      3. Chapter 22: Understanding the Excel Object Model and Key Objects
        1. Getting an Overview of the Excel Object Model
        2. Understanding Excel's Creatable Objects
        3. Managing Workbooks
        4. Working with Worksheets
        5. Working with the Active Cell or Selection
        6. Working with Ranges
        7. Setting Options
        8. The Bottom Line
      4. Chapter 23: Working with Widely Used Objects in Excel
        1. Working with Charts
        2. Working with Windows
        3. Working with Find and Replace
        4. Adding Shapes
        5. The Bottom Line
      5. Chapter 24: Understanding the PowerPoint Object Model and Key Objects
        1. Getting an Overview of the PowerPoint Object Model
        2. Understanding PowerPoint's Creatable Objects
        3. Working with Presentations
        4. Working with Windows and Views
        5. Working with Slides
        6. Working with Masters
        7. The Bottom Line
      6. Chapter 25: Working with Shapes and Running Slide Shows
        1. Working with Shapes
        2. Working with Headers and Footers
        3. Setting Up and Running a Slide Show
        4. The Bottom Line
      7. Chapter 26: Understanding the Outlook Object Model and Key Objects
        1. Getting an Overview of the Outlook Object Model
        2. Working with the Application Object
        3. Understanding General Methods for Working with Outlook Objects
        4. Working with Messages
        5. Working with Calendar Items
        6. Working with Tasks and Task Requests
        7. Searching for Items
        8. The Bottom Line
      8. Chapter 27: Working with Events in Outlook
        1. Working with Application-Level Events
        2. Working with Item-Level Events
        3. Understanding Quick Steps
        4. The Bottom Line
      9. Chapter 28: Understanding the Access Object Model and Key Objects
        1. Getting Started with VBA in Access
        2. Getting an Overview of the Access Object Model
        3. Understanding Creatable Objects in Access
        4. Opening and Closing Databases
        5. Working with the Screen Object
        6. Using the DoCmd Object to Run Access Commands
        7. The Bottom Line
      10. Chapter 29: Manipulating the Data in an Access Database via VBA
        1. Understanding How to Proceed
        2. Preparing to Manage the Data in a Database
        3. Opening a Recordset
        4. Accessing a Particular Record in a Recordset
        5. Searching for a Record
        6. Returning the Fields in a Record
        7. Editing a Record
        8. Inserting and Deleting Records
        9. Closing a Recordset
        10. Saving a Recordset to the Cloud
        11. The Bottom Line
      11. Chapter 30: Accessing One Application from Another Application
        1. Understanding the Tools Used to Communicate between Applications
        2. Using Automation to Transfer Information
        3. Using the Shell Function to Run an Application
        4. Using Data Objects to Store and Retrieve Information
        5. Communicating via DDE
        6. Communicating via SendKeys
        7. Going beyond VBA
        8. The Bottom Line
      12. Chapter 31: Programming the Office 2013 Ribbon
        1. What Is XML?
        2. Hiding the Editing Group on the Word Ribbon
        3. Working with Excel and PowerPoint
        4. Undoing Ribbon Modifications
        5. Selecting the Scope of Your Ribbon Customization
        6. Adding a New Group
        7. Adding Callbacks
        8. Adding Attributes
        9. Using Menus and Lists
        10. Toggling with a Toggle-Button Control
        11. Modifying the Ribbon in Access
        12. Adding a Callback in Access
        13. What to Look For If Things Go Wrong
        14. Where to Go from Here
        15. The Bottom Line
    17. Appendix: The Bottom Line
      1. Chapter 1: Recording and Running Macros in the Office Applications
      2. Chapter 2: Getting Started with the Visual Basic Editor
      3. Chapter 3: Editing Recorded Macros
      4. Chapter 4: Creating Code from Scratch in the Visual Basic Editor
      5. Chapter 5: Understanding the Essentials of VBA Syntax
      6. Chapter 6: Working with Variables, Constants, and Enumerations
      7. Chapter 7: Using Array Variables
      8. Chapter 8: Finding the Objects, Methods, and Properties You Need
      9. Chapter 9: Using Built-in Functions
      10. Chapter 10: Creating Your Own Functions
      11. Chapter 11: Making Decisions in Your Code
      12. Chapter 12: Using Loops to Repeat Actions
      13. Chapter 13: Getting User Input with Message Boxes and Input Boxes
      14. Chapter 14: Creating Simple Custom Dialog Boxes
      15. Chapter 15: Creating Complex Forms
      16. Chapter 16: Building Modular Code and Using Classes
      17. Chapter 17: Debugging Your Code and Handling Errors
      18. Chapter 18: Building Well-Behaved Code
      19. Chapter 19: Securing Your Code with VBA's Security Features
      20. Chapter 20: Understanding the Word Object Model and Key Objects
      21. Chapter 21: Working with Widely Used Objects in Word
      22. Chapter 22: Understanding the Excel Object Model and Key Objects
      23. Chapter 23: Working with Widely Used Objects in Excel
      24. Chapter 24: Understanding the PowerPoint Object Model and Key Objects
      25. Chapter 25: Working with Shapes and Running Slide Shows
      26. Chapter 26: Understanding the Outlook Object Model and Key Objects
      27. Chapter 27: Working with Events in Outlook
      28. Chapter 28: Understanding the Access Object Model and Key Objects
      29. Chapter 29: Manipulating the Data in an Access Database via VBA
      30. Chapter 30: Accessing One Application from Another Application
      31. Chapter 31: Programming the Office 2013 Ribbon
    18. Index

    Product information

    • Title: Mastering VBA for Microsoft Office 2013
    • Author(s):
    • Release date: August 2013
    • Publisher(s): Sybex
    • ISBN: 9781118695128