Calling functions
Using a custom function from within Excel, the way we did just now, has some value. If nothing else, it's an effective way of testing whether the function works or not. However, the point of writing VBA code is to automate your work. In other words, ideally, we want to run custom functions like a standard Sub
procedure, either by pressing F5 in the VBA Editor or by pressing a command button in Excel.
The only way to do that is to write an extra Sub
procedure, which we know can be executed, and then call the function. By calling, we mean calling up the non-executable function to do its work via the Sub
procedure.
In this recipe, we will be calling a function.
Getting ready
Make sure that CustomFuntions.xlsm
is still open and the VBA Editor is active.
How to do it…
These are the steps to call a function:
- Add the following
Sub
procedure below the two custom functions inModule1
:Sub InsertNewSheet() Â Â Â Â Worksheets...