• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

II. The VBA Programming Language > 6. Functions and Subroutines

Chapter 6. Functions and Subroutines

As we have seen, VBA allows two kinds of procedures: functions and subroutines. As a reminder, the only difference between a function and a subroutine is that a function returns a value, whereas a subroutine does not.

Calling Functions

A function declaration has the form:

[Public or Private] Function FunctionName(Param1 As DataType1, _
         Param2 As DataType2,...) As ReturnType

Note that we must declare the data types not only of each parameter to the function, but also of the return type. Otherwise, VBA declares these items as variants.

We will discuss the optional keywords Public and Private later in this chapter, but you can probably guess that they are used here to indicate the scope of the function, just as they are used in variable declarations.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint