OK, here's the long answer to why your first construct doesn't work -- probably way more than you wanted to know.
It has to do with the parens.
When you invoke a Sub with Call, you must use parens around the arguments:
When you assign the result of a function to a variable, you must use parens around the arguments:
myResult = MyFunc(arg1, arg2)
If you want to pass arguments ByVal (by value, a copy of the variable) or ByRef (by reference, a pointer to the variable), according to the procedure's signature, you don't include parens:
MySub arg1, arg2
MyFunc arg1, arg2
If you want to pass arguments ByVal, irrespective of the procedure’s signature (which won't work for a procedure expecting an array (because arrays are always passed by reference) or an object), you enclose the argument in parens, or an extra set of parens. In the examples below, arg1 is passed by value, and arg2 according to the procedure’s signature:
Call MySub((arg1), arg2)
myResult = MyFunc((arg1), arg2)
MySub (arg1), arg2
MyFunc (arg1), arg2
That’s because when you add parens around an argument that doesn't require them, the argument is evaluated, and the result of the evaluation is passed to the procedure. It means the argument is passed by value regardless of how the procedure requested it.
That also explains why you can't use parens around two or more arguments when they are not required; the evaluation of (arg1) may be meaningful, but the evaluation of (arg1, arg2) is not. That's why this generates an error:
Msgbox (Prompt:=arg1, Title:=arg2, Buttons:=arg3)
(That example is exactly analogous to your IIf)
That also explains why if you call a procedure expecting a range with parens where none are required, you get a type mismatch error; because the evaluation of a range is a Variant, or Variant/Array.
You can't pass a Variant ByRef as a static type (Long, String, ...).
You can pass a statically-typed variable ByRef as a Variant, and the called procedure can modify its value with data of the appropriate (or coercible) type.
So: Parens means completely different things according to context. VBA might have used some other bookends (curly braces, square brackets, whatever) to indicate enclosing a list of arguments versus a call for evaluation, but it didn't.
Since objects are always passed ByRef, you can never put unnecessary parens around an object variable. Chip Pearson (http://www.cpearson.com/excel/byrefbyval.aspx) explains the meaning of ByRef and ByVal for an object variable:
The ByRef and ByVal modifiers indicate how the reference is passed to the called procedure. When you pass an object type variable to a procedure, the reference or address to the object is passed -- you never really pass the object itself. When you pass an object ByRef, the reference is passed by reference and the called procedure can change the object to which that reference refers to. When an object is passed ByVal, a copy of the reference (address) of the object is passed.
Bookmarks