Chapter 10. Creating Your Own Functions

In Chapter 9, you learned how to use VBA's built-in functions. In this chapter, you'll learn how to create your own functions. As you'll see, you create a function just like you create a subprocedure: by working in the Code window in the module in which you want to store the function. (You can't record a function in Excel and Word—the applications that provide a Macro Recorder. Instead, you have to write functions yourself because the two recorders create only subprocedures.)

It's important to note that, although both are procedures, functions differ from subs. The primary difference is that functions interact more with other procedures: They accept arguments (incoming data) from the procedure that calls ...

Get Mastering VBA for Microsoft® Office 2010 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.