单击VBA下拉

时间:2015-02-25 16:52:51

标签: excel vba excel-vba

我有一个小宏,可以在单元格 B2

中建立数据验证下拉菜单
Sub InternalString()
    Range("B2").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="alpha,beta,gamma,delta"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

宏也选择 s单元格。我想在宏中添加一些内容,然后点击"在下拉菜单中,一旦控件返回给用户,他们就会看到:

enter image description here

欢迎任何建议。

1 个答案:

答案 0 :(得分:1)

根据建议here进行修改,似乎SendKeys应该可以解决问题:

Sub InternalString()
    Range("B2").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="alpha,beta,gamma,delta"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With

    '"Show" the validation list as a dropdown:
    Application.SendKeys ("%{DOWN}")
End Sub