O'Reilly logo

Microsoft® Outlook® 2007 Bible by Peter G. Aitken

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required