M
Matthew Herbert
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
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