Use Enum for dropdown function arguments

Tested in Excel 365 (16.8730.2046) 64-bit

There are cases when your functions gets arguments that are not so easy to remember or are prone to be misspelled. A dropdown list with possible arguments would save a lot of time. This can be achieved by creating a user defined type using enum. Here are some examples:

  1. Public Enum ENM_RegistryOperation
  2.     RegistryRead
  3.     RegistryWrite
  4.     RegistryDelete
  5. End Enum
  6. '
  7. Public Enum ENM_RegistryKeyType
  8.     REG_SZ
  9.     REG_EXPAND_SZ
  10.     REG_DWORD
  11. End Enum
  12. '
  13. Public Enum ENM_FileOpenType
  14.     FileRead
  15.     FileAppend
  16.     FileOverwrite
  17.     FileRandom
  18.     FileBinary
  19. End Enum

First 2 types are used in this example.

The third one is used in this example.

You can also use Enum to store specific values under a more user friendly name.

  1. Public Enum myOS
  2.     Windows7 = 6.1
  3.     Windows8 = 6.2
  4.     Windows81 = 6.3
  5.     Windows10 = 10
  6.     ' etc
  7. End Enum

See all Windows version here.

Later edit: I have found more info and examples about Enum on this site.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.