Search notes:

VBA - language: keyword optional

Optional parameters allow to define default values for sub/function parameters that need not be specified when the sub/function is called.
' runVBAFilesInOffice.vbs -word %CD%\keyword-optional -c main

sub main() 

  call xyz("one", "two", "three") 
  call xyz("apple", "bananana") 
  call xyz("Berlin", param_3 := "Paris") 

  activeDocument.saved = true 

 end sub 
 

 private sub xyz (                         _ 
                param_1 as string        , _ 
       optional param_2 as string = "foo", _ 
       optional param_3 as string = "bar"  _ 
 ) 

     selection.typeText param_1 & " - " & param_2 & " - " & param_3 & chr(13) 

 end sub 
Github repository about-VBA, path: /language/subs-and-functions/optional-parameters/keyword-optional.bas
Note that optional parameters must have a constant default value. It's not allowed to define an optional parameter that takes the return value of a function like now (the corresponding compilation error is Constant expression required).
For truly optional parameters (that is: optional parameters without specifying a default value), isMissing() can be used to check if an actual value was passed for the argument.

See also

VBA language

Index