Calling a Procedure

To execute the code in a procedure—in other words, to call the procedure—you use a different syntax for sub- and function procedures. Because a function returns a value, it is an expression, and you call it by referring to it anywhere an expression could be used. Perhaps most commonly, a function is called by referring to it on the right side of an assignment statement. If you have a function named HalfOf, for example, you could call it and assign the return value to X as follows:

x = HalfOf(y)

Or, you could call the function and display the return value in the Immediate window:

Debug.Print HalfOf(104)

Calling sub procedures is different. Because they do not return a value, they cannot be treated as an expression. You ...

Get Office® XP Development with VBA 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.