I am trying to write a VBA sub that allows optional parameters with default values. I tried the sample code from Microsoft Docs - Optional Parameters (Visual Basic) but it leads to the sub not showing on list of available subs (i.e. from View Macros).
Sub notify(ByVal company As String, Optional ByVal office As String = "QJZ")
If office = "QJZ" Then
Debug.WriteLine("office not supplied -- using Headquarters")
office = "Headquarters"
End If
' Insert code to notify headquarters or specified office.
End Sub
The sub declaration I tried, but couldn't get to appear, was:
Sub HighlightByFont( _
Optional ByVal highlightFont As Variant = "", _
Optional ByVal highlightColor As Variant = "", _
Optional ByVal highlightText As Variant = "", _
Optional ByVal matchWildcards As Variant = False, _
Optional ByVal useGUI As Variant = False, _
Optional ByVal highlightBold As Variant = False, _
Optional ByVal highlightItalic As Variant = False)
For now, I have had to settle for the below with IsMissing logic:
Sub HighlightByFont( _
Optional ByVal highlightFont As Variant, _
Optional ByVal highlightColor As Variant, _
Optional ByVal highlightText As Variant, _
Optional ByVal matchWildcards As Variant, _
Optional ByVal useGUI As Variant, _
Optional ByVal highlightBold As Variant, _
Optional ByVal highlightItalic As Variant)
Is it (still†) possible, and if so, how:
- to set up the parameter declaration?
- to get it to appear in the View Macros list?
Environment:
- Word 2016 x64
- Windows 10
† All references, including SO answers related to VBA optional paramaters are from 2015.