How To: Excel user defined function with user defined argument constants/structures

Kevin McCartney 21 Reputation points
2022-06-17T11:14:16.25+00:00

Hi to whom it may concern,

within Excel VBA, is it possible for a user defined function to provide predefined constant/structure values for the each potential declared argument, just like other internal VBA functions already do?

i.e. for illustration purposes, take say the VBA MsgBox function, we can see here for the 'Button' argument its default value is pre-set to vbOKOnly, but there's a provided list of argument constant/structure values that a user can select from.

212400-msgbox.png

... hence my question, can a user defined function replicate the same visual functionality but with a user defined list of constant/structure values in order to limit what a user can select?

Thankyou in advance.

Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,750 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 45,776 Reputation points
    2022-06-17T11:24:45.053+00:00

    Sure, it's a simple enum(eration)
    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/enum-statement

    Public Enum enuTest  
        enuTest01 = 1  
        enuTest02 = 2  
    End Enum  
      
    Public Test()  
        Dim enu As enuTest  
          
        enu = enuTest01  
    End  
    

    212473-image.png

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.