VBA函数参数列表选择

jas*_*n m 6 excel vba excel-2007 excel-vba

我希望做以下事情:

    Public Function myFunc(vArg1 as string, vArg2 as string, vArg3 as ["A","B","C"])


    End Function
Run Code Online (Sandbox Code Playgroud)

用户在调用vArg3时获取vArg3的下拉列表.这将类似于以下内容:

            Public Sub Main()
                Call StrComp("A", "B", vbTextCompare)
            End Sub
Run Code Online (Sandbox Code Playgroud)

其中vbTextCompare可以从预定义的列表或函数的参数中选择.

谢谢

Fin*_*ink 11

这就是所谓的枚举.这是一个简单的例子:

Public Enum DayOfWeek
    Monday = 1
    Tuesday = 2
    Wednesday = 3
    Thursday = 4
    Friday = 5
    Saturday = 6
    Sunday = 7
End Enum

Public Function GetDrinkSpecial(day As DayOfWeek) As String

    Select Case day
        Case DayOfWeek.Monday
            GetDrinkSpecial = "$1 Tap Domestics"
        Case DayOfWeek.Tuesday
            GetDrinkSpecial = "2 for 1 Rail Mixers"
        Case DayOfWeek.Wednesday
            GetDrinkSpecial = "$2 You-Call-Its"
        Case DayOfWeek.Thursday
            GetDrinkSpecial = "$1 Bush Bottles"
        Case DayOfWeek.Friday
            GetDrinkSpecial = "$3 Greenies"
        Case DayOfWeek.Saturday
            GetDrinkSpecial = "No Specials, Doh!"
        Case DayOfWeek.Sunday
            GetDrinkSpecial = "No Specials, Doh!"
        Case Else
            GetDrinkSpecial = "No Specials, Doh!"
    End Select
End Function

Public Sub TestIt()

    MsgBox GetDrinkSpecial(Monday)
    MsgBox GetDrinkSpecial(Tuesday)
    MsgBox GetDrinkSpecial(Wednesday)
    MsgBox GetDrinkSpecial(Thursday)
    MsgBox GetDrinkSpecial(Friday)
    MsgBox GetDrinkSpecial(Saturday)
    MsgBox GetDrinkSpecial(Sunday)
End Sub
Run Code Online (Sandbox Code Playgroud)

这将在VBA编辑器中调用函数时获得所需的"下拉"效果.但是,如果要从excel单元格公式中调用"GetDrinkSpecial",则无法访问枚举,并且需要专门传递枚举的long值.