O'Reilly logo

Programming Excel with VBA and .NET by Steve Saunders, Jeff Webb

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

Procedures

Procedures are named blocks of code that perform a task. I’ve shown a lot of procedures already and I feel a little bad about waiting this long to define that term. Procedures can have arguments , which let you pass values in to the procedure from somewhere, and they may return values through their name. Figure 2-5 illustrates these parts using the CubeRoot example from Chapter 1.

Visual Basic has four kinds of procedures:

Sub procedures

Perform a task but don’t have return values.

Function procedures

Perform a task and return a value as their result.

Parts of a procedure

Figure 2-5. Parts of a procedure

Property procedures

Get or set a value in an object or module.

Event procedures

A special kind of Sub procedure that respond to events that occur in Excel. Only classes can contain event procedures.

The following sections explain these different types of procedures and how you use them.

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