O'Reilly logo

Excel® 2007 Power Programming with VBA by John Walkenbach

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 9. Working with VBA Sub Procedures

In This Chapter

A procedure holds a group of Visual Basic for Applications (VBA) statements that accomplishes a desired task. Most VBA code is contained in procedures. This chapter focuses on Sub procedures.

  • Declaring and creating VBA Sub procedures

  • Executing procedures

  • Passing arguments to a procedure

  • Using error-handling techniques

  • An example of developing a useful procedure

Cross-Reference

Cross-Reference

VBA also supports Function procedures, which I discuss in Chapter 10. Chapter 11 has many additional examples of procedures, both Sub and Function, that you can incorporate into your work.

About Procedures

A procedure is a series of VBA statements that resides in a VBA module, which you access in the Visual Basic Editor (VBE). A module can hold any number of procedures.

You have a number of ways to call, or execute, procedures. A procedure is executed from beginning to end, but it can also be ended prematurely.

Tip

Tip

A procedure can be any length, but many people prefer to avoid creating extremely long procedures that perform many different operations. You may find it easier to write several smaller procedures, each with a single purpose. Then, design a main procedure that calls those other procedures. This approach can make your code easier to maintain.

Some procedures ...

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