Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Parentheses In Code Statements and Calls
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

The purpose of this Microsoft Word Tips & Microsoft Word Help page is to explain and provide examples of when to use parentheses in code statements and calls.

  1. Each Sub or Function statement must as a minimum include empty parentheses ().  The parentheses in Sub or Function statements demark the parameters (or arguments) list.  If there are no arguments the parentheses are empty
  2. :
  3. Calls to functions that take arguments must include parentheses around the passed arguments:.
  4. Parentheses are not used in direct calls to subs that take arguments:
  5. However, parentheses are required in indirect calls (calls using the keyword Call) to subs that take arguments:

Site Note IconNote:  I don't think I have ever used the Call keyword. You probably shouldn't either. Other than having to remember one rule instead of two, it makes no difference.

  1. When dealing with methods of objects or VBA functions the use of parentheses depends on whether the method or function is returning a value (i.e., If =, set =, etc.):
VBA Script:
Sub Demo()
  MsgBox "Fine as is. No parentheses required", vbOKOnly, "LOOK MOM NO PARENS"
  If MsgBox("Do you see how parentheses is required here?", _
             vbQuestion + vbYesNo, "PARENS REQUIRED") = vbYes Then
    MsgBox "There you go!"
  Else
    Beep
    MsgBox "Try again."
  End If
End Sub

Site Note IconSee: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

That's it! I hope you have found this tips page useful and informative.

Share

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

Click to donate British Pound Sterling                   Click to donate US dollars                   Click to donate EU euros

Search my site or the web using Google Search Engine

Google Search Logo