Chapter 25. Programming Outlook with VBA: Some Examples

IN THIS CHAPTER

  • Organizing email messages by subject

  • Listing the next week's appointments

In the previous two chapters, you learned a lot of details about the VBA programming language and the Outlook Object Model. This information is essential, but it can also be a terrific learning aid to see these concepts put into use in a real-world situation. To this end, this chapter presents two complete and tested Outlook VBA applications that perform tasks that Outlook users really might want to perform. You can use these projects as-is, modify them to suit your specific needs, or simply use them as learning aids.

Organizing Email Messages Based on Subject

You had an introduction to this project in Chapter 24. This chapter goes into a lot more detail and presents a complete, working application.

At the heart of this application is a VBA function called MoveMessagesBySubject(). It takes two arguments:

  • The text that you are searching for

  • The name of the destination folder

The function's return value is type Boolean. It returns True if the code completes successfully and False if there was a problem. The most likely problem that might occur is that the destination folder cannot be found. However, the function includes error handling code to deal with unforeseen errors.

The function MoveMessagesBySubject() is presented in Listing 25.1. Note that this function calls the function FindFolder(), which was presented in Chapter 24. In other words, FindFolder() ...

Get Microsoft® Outlook® 2007 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.