VBA Choose 函数从其参数列表中返回一个给定数字的值。
Choose(数字、值_1、值_2、值_3 等)
按“choice”变量中写入的数字显示 3 个值之一:
Sub ChooseExample1() choice = 1 course = Choose(choice, "Excel", "VBA", "Google Sheets") MsgBox "所选课程:" & course '返回消息:“所选课程:Excel” End Sub
Choose 函数的替代方法是使用数组 (Array):
Sub ChooseExample2() choice = 1 course = Array("Excel", "VBA", "Google Sheets")(choice) MsgBox "所选课程:" & course '返回消息:“所选课程:VBA” End Sub