在另一个userform中使用来自userform的VBA sub

时间:2016-09-24 16:29:02

标签: excel vba excel-vba

因为我遇到了这个问题,所以我被困在我的程序中。基本上,有一个Public Sub,我在其中引用UserForm1控件,我需要在UserForm2中运行此Sub。例如:

[某些模块中的代码]

<ui:composition template="/WEB-INF/template/LayoutPadrao.xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <ui:define name="titulo">Relatório de entradas emitidas</ui:define>

    <ui:define name="corpo">
        <h:form id="frm">
            <h1>Relatório de entradas emitidas</h1>

            <p:messages autoUpdate="true" closable="true" />

            <p:toolbar style="margin-top: 20px">
                <p:toolbarGroup>
                    <p:commandButton value="EmitirPdf"
                        action="#{relatorioEntradasBean.emitirPdf}" ajax="false" />
                    <p:commandButton value="EmitirXls"
                        action="#{relatorioEntradasBean.emitirXls}" ajax="false" />
                </p:toolbarGroup>
            </p:toolbar>

            <p:panelGrid columns="7" id="painel"
                style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
                <p:outputLabel value="Data de criação" />
                <h:panelGroup>
                    <p:calendar value="#{relatorioEntradasBean.dataInicio}"
                        label="Data inicial" pattern="dd/MM/yyyy" size="8" />
                    <p:spacer width="8" />
                    <h:outputText value="a" />
                    <p:spacer width="8" />
                    <p:calendar value="#{relatorioEntradasBean.dataFim}"
                        label="Data final" pattern="dd/MM/yyyy" size="8" />
                </h:panelGroup>
                <h:panelGroup>
                    <p:outputLabel value="Cliente" for="cliente" />
                    <p:autoComplete id="cliente" size="40" dropdown="true"
                        value="#{relatorioEntradasBean.cliente}"
                        completeMethod="#{cadastroEntradaBean.completarCliente}"
                        var="cliente" itemLabel="#{cliente.nome}" itemValue="#{cliente}"
                        forceSelection="true" />
                </h:panelGroup>


                <p:outputLabel value="Status" />
                <h:panelGroup>
                    <p:selectOneMenu id="statusEntrada"
                        value="#{relatorioEntradasBean.statusEntrada}">
                        <f:selectItem itemLabel="Selecione" />
                        <f:selectItems value="#{enumProviderStatus.statusEntradas}"
                            var="statusEntrada" itemValue="#{statusEntrada}"
                            itemLabel="#{statusEntrada.descricao}" />
                    </p:selectOneMenu>
                </h:panelGroup>
            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

[UserForm2中的代码]

Public Sub example()
If IsEmpty(ListBox1) Then Var = 1 Else Var = 0
End Sub

ListBox1是UserForm1中的一个控件。当我执行这样的程序时,问题是我在UserForm2中调用示例Sub时出现“Object Required(Error 424)”的错误。那么,有没有办法解决这个问题呢?

抱歉我的英语不好,这不是我的母语。

提前致谢!

编辑:

[模块中的实际代码]

Private Sub UserForm_Click()
example
End Sub

[UserForm2中的实际代码]

Public Sub atualizarlistas6()

For i = 0 To (lstAliados6.ListCount - 1)
    elementoslst = Split(lstAliados6.List(i))
    Set lista = Worksheets("Combate").Range("1:1").Find(elementoslst(0), LookIn:=xlValues, LookAt:=xlPart)
    lstAliados6.RemoveItem i
    lista.Activate
    linha = ActiveCell.Value & " |HP:" & ActiveCell.Offset(1, 0).Value & " |MP:" & ActiveCell.Offset(2, 0).Value & _
    " |PP:25 |Desloc.:" & ActiveCell.Offset(4, 0).Value & "cm |Alcance:" & ActiveCell.Offset(5, 0).Value & "cm |DnT:" _
    & ActiveCell.Offset(6, 0).Value & "+" & ActiveCell.Offset(7, 0).Value & ".3d10# |DfT:" & ActiveCell.Offset(8, 0).Value _
    & " |Ref.:" & ActiveCell.Offset(9, 0).Value & " |CM:" & ActiveCell.Offset(10, 0).Value & " |Agi.:" & ActiveCell.Offset(11, 0).Value
    lstAliados6.AddItem linha, i
    Next i

End Sub

0 个答案:

没有答案