View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_4_] Bob Phillips[_4_] is offline
external usenet poster
 
Posts: 834
Default Loop Enumeration Constants

I wouldn't have thought so, as a Enum list is just a set of integers with a
descriptive handle assigned to them. If it were in the OS somewhere maybe,
but this would be within VB as far as I can see.

HTH

Bob

"Matthew Herbert" wrote in
message ...
All,

I'm curious to know if there is a way to loop through the constants of an
enumeration. (Or, maybe another way to put this is this: Is there a way
to
get an enumeration as a collection?)

I'll illustrate with a simple example below ("TestEnumLoop"), which puts
the
constants of XlYesNoGuess into an array, loops through the array, and
prints
the constant values to the Immediate Window. (Continue reading after
"TestEnumLoop" for the "hypothetical code").

Sub TestEnumLoop()
Dim varArr As Variant
Dim varItem As Variant
'Dim xlEnum As XlYesNoGuess

varArr = Array(xlGuess, xlNo, xlYes)

For Each varItem In varArr
Debug.Print varItem
Next varItem

End Sub

So, I'm curious to know if there is some way to loop through the
"collection" of constants for a given enumeration. For example, is there
something that would exist for the "hypothetical code" below?

Sub HypotheticalLoop()
Dim xlEnum As XlYesNoGuess

For Each xlEnum In XlYesNoGuess
Debug.Print xlEnumTest
Next xlEnum

End Sub

Thanks,

Matthew Herbert