VBA basics
25. About named arguments

Excel macro basics and applications, introduction to Excel VBA
last updated:08-30-2019

25. About named arguments

Some of this topic was processed by machine translation. Original

An argument is a specification of a value passed when calling a function or method.
There is a named argument as a description method when passing this argument.

In the macro VBA description,: = is used.
This: = is used only for named arguments.

Formal and actual arguments

A formal argument is an argument used when defining a function or method.
An actual argument is an argument that is passed when the function or method is actually used.
In this macro VBA series, they are simply expressed as “arguments” without distinguishing between them.

What is a method?

method and method / method. Specify the operation / operation for the object.
Select a cell, delete a cell, etc., but I will explain a little bit in the future.

Understand Excel words (objects, properties, methods)

About named arguments

Normally, if there are multiple arguments, specify them in that order.
From the beginning
1st argument, 2nd argument, 3rd argument, ...
Call it.
When there are a lot of arguments, conscious of what number is cumbersome and confusing.
The argument is named so that it can be specified by that name.
that is,
Named argument.

If you specify a named argument:
Named argument name: = value
In this way, specify the value with: =.

Example of named argument

An example of using named arguments in the MsgBox function.

MsgBox(prompt[, buttons] [, title] [, helpfile, context])

MsgBox "I'm done", vbOKOnly, "Title"

However, this argument must be specified in order.
If you use a named argument,

MsgBox prompt:="I'm done", Buttons:=vbOKOnly, Title:="Title"

this is,

MsgBox Title:="Title", Buttons:=vbOKOnly, prompt:="I'm done"

If you use named arguments like this, you can safely change the order.
If you do not use named arguments, omit intermediate arguments,

MsgBox "I'm done", , "Title"

Thus, the position of the argument must be specified correctly, such as,,.
But if you use named arguments,

MsgBox prompt:="I'm done", Title:="Title"

If you use named arguments like this, you can specify them without being aware of the position of the arguments.

The need for named arguments

It is desirable to use named arguments whenever possible.
Using named arguments in all functions / methods can be a bit cumbersome.

Like the MsgBox function in the example above,
Many functions know the order of their arguments and often do not need to use named arguments.
Some methods require many arguments to be specified,
Few people remember the order of the arguments.
Using named arguments makes the macro VBA easier to understand.
That means
Think of named arguments as something that makes macro VBA easier to read.

Articles with the same theme "VBA basics"

22. Conditional branch (Select Case)
23. Message box (MsgBox function)
24. Input box (InputBox function)
25. About named arguments
26. General practice question 2
27. Select book / sheet (Select, Activate)
28. Select cell / row / column (Select, Activate)
29. Delete / Insert cell / row / column (Delete, Insert)
30. General practice question 3
31. Format Cells (display format, NumberFormatLocal)
32. Format Cells (Alignment)

  • >
  • >
  • 25. About named arguments

  • If you find this site useful, please share and bookmark.

    I'm going to pay close attention to the description,
    If you have any mistakes or suggestions,「Contact Us」I hope you will let me know.
    Use the posted VBA code at your own risk.
    We are not liable for any damages such as data corruption.

    If you find this site useful, please share and bookmark.
    To the bottom of the text