Does the method return a value you need? Use parentheses (but optional if not passing any arguments to the method unless you're using the return value in the same line).
Eg - below RowRange
returns a Range
object, but you can't then index directly into it using (2,1), since that is interpreted as passing arguments to RowRange
(which doesn't take any)
s = myPivotTable.RowRange(2, 1).Value 'fails with "too many parameters"
Adding the parentheses clean this up:
s = myPivotTable.RowRange()(2, 1).Value 'OK
Using Call ? Use parentheses. But Call is typically considered as deprecated.
Anything else? Parentheses not required, and may produce unexpected outcomes by causing arguments to be evaluated before being passed.
One thing to watch out for is when the Vb editor puts a space between the method name and the opening parenthesis - when that happens it's a sign you might not need the parentheses at all.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…