VBA宏:无法识别验证

时间:2018-10-29 17:39:38

标签: excel vba excel-vba

我正在尝试创建一个下拉列表,但是MF_E_VIDEO_RECORDING_DEVICE_INVALIDATED一直出现在IMFCaptureEngineOnEventCallback函数中,一直到<body> <ui:composition template="./TemplateDefault.xhtml"> <ui:define name="content"> <h:outputStylesheet name="./css/modules.css" /> <p:dataTable var="user" value="#{user.getList()}"> <f:facet name="header"> USER LIST </f:facet> <p:column headerText="Id" style="width:5%"> <h:outputText value="#{user.id}" /> </p:column> <p:column headerText="Name" style="width:20%"> <h:outputText value="#{user.name}" /> </p:column> <p:column headerText="Password" style="width:20%"> <h:outputText value="#{user.pwd}" /> </p:column> <p:column headerText="Email" style="width:20%"> <h:outputText value="#{user.email}" /> </p:column> <p:column headerText="Options" style="width:15%"> <h:form> <p:growl id="message" showDetail="true" /> <p:commandButton actionListener="#{loginFormBean.msgDelete}" update="message" icon="ui-icon-trash" title="Delete User" > <p:confirm header="Confirm" message="Are you sure?" icon="ui-icon-alert"/> </p:commandButton> <p:confirmDialog global="true"> <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" /> <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" /> </p:confirmDialog> </h:form> </p:column> <f:facet name="footer"> Found #{user.getList().size()} users. </f:facet> </p:dataTable> </ui:define> </ui:composition> </body>

我尝试过:

  • 删除error 1004 'Application-defined or object-defined error'
  • 将所有内容都放在一行中
  • 卸下括号并将“ .Add”移至下一行
  • 复制我在网上找到的有效的验证功能

我不知道怎么了。我认为可能无法识别,但不确定。

.add

1 个答案:

答案 0 :(得分:2)

请勿在您的.Add中使用With Block

Sheets("Sheet1").Range("C2").Offset(0, 3).Select

With Selection.Validation
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=$B$2:$B$5"
    .IgnoreBlank = True
    .InCellDropdown = True
End With

我建议避免使用.Select并声明您的范围变量。

Dim myRng As Range
Set myRng = ThisWorkbook.Worksheets("Sheet1").Range("F2")

With myRng.Validation
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=$B$2:$B$5"
    .IgnoreBlank = True
    .InCellDropdown = True
End With

使用.delete确保您当前未在其中设置验证可能不是一个坏主意-如果您先前已经进行过数据验证,则可能会引发错误。

>
With myRng.Validation
    .delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                xlBetween, Formula1:="=$B$2:$B$5"
    .IgnoreBlank = True
    .InCellDropdown = True
End With