Should I use Call keyword in VB/VBA?

Ah ha. I have long wondered about this and even reading a two inch thick book on VBA basically says don’t use it unless you want to use the Find feature of the VBE to easily find calls in large projects.

But I just found another use.

We know that it’s possible to concatenate lines of code with the colon character, for example:

Function Test(mode as Boolean) 
    if mode = True then x = x + 1 : Exit Sub
    y = y - 1
End Sub

But if you do this with procedure calls at the beginning of a line, the VBE assumes that you’re referring to a label and removes any indents, aligning the line to the left margin (even though the procedure is called as intended):

Function Test()
Function1 : Function2
End Function

Using the Call statement allows concatenation of procedure calls while maintaining your code indents:

Function Test()
    Call Function1 : Call Function2
End Function

If you don’t use the Call statement in the above example, the VBE will assume that “Function1” is an label and left align it in the code window, even though it won’t cause an error.

Leave a Comment