Using parentheses in code
Sub procedures, built-in statements, and some methods don't return a value, so the arguments aren't enclosed in parentheses. For example:
MySub "stringArgument", integerArgument
Function procedures, built-in functions, and some methods do return a value, but you can ignore it. If you ignore the return value, don't include parentheses. Call the function just as you would call a Sub procedure. Omit the parentheses, list any arguments, and don't assign the function to a variable. For example:
MsgBox "Task Completed!", 0, "Task Box"
To use the return value of a function, enclose the arguments in parentheses, as shown in the following example.
Answer3 = MsgBox("Are you happy with your salary?", 4, "Question 3")
A statement in a Sub or Function procedure can pass values to a called procedure by using named arguments. The guidelines for using parentheses apply, whether or not you use named arguments. When you use named arguments, you can list them in any order, and you can omit optional arguments. Named arguments are always followed by a colon and an equal sign (:=), and then the argument value.
The following example calls the MsgBox function by using named arguments, but it ignores the return value.
MsgBox Title:="Task Box", Prompt:="Task Completed!"
The following example calls the MsgBox function by using named arguments and assigns the return value to the variable.
answer3 = MsgBox(Title:="Question 3", _
Prompt:="Are you happy with your salary?", Buttons:=4)
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기