Search notes:

VBA - language: keyword isMissing

isMissing() is a VBA function to check if an optional parameter was given a value.
Unfortunately, it does not distinguish between passing null or not explicitly stating a value.
The data type of a parameter that needs to be checked with isMissing() needs to be a variant.
option explicit

sub main() ' {

  call xyz("one", "two")
  call xyz("apple")
  call xyz(param_2 := "banana")
  call xyz
  call xyz(param_2 :=  null)

  activeDocument.saved = true

 end sub  ' }


' xyz {
private sub xyz (                   _
       optional param_1 as variant, _
       optional param_2 as variant  _
)

     if isMissing(param_1) then
        selection.typeText("param_1 is missing")
     else
        selection.typeText("param_1 = " & param_1)
     end if

     if isMissing(param_2) then
        selection.typeText(" - param_2 is missing")
     else
        selection.typeText(" - param_2 = " & param_2)
     end if

     selection.typeText chr(13)

end sub  ' }
Github repository about-VBA, path: /language/subs-and-functions/optional-parameters/keyword-isMissing.bas

See also

VBA language

Index