Listmover事件在运行时仅触发一次

时间:2018-08-10 09:15:44

标签: vba excel-vba word-vba

我有两个输入和输出列表框,我想将项目从一个移到另一个。因此,我使用以下变量制作了一个类(CListMover):

Option Explicit

Private m_blnRemoveOnMove As Boolean
Private m_DeleteItemFromList As Boolean
Private m_ReverseListBox As Boolean

Public WithEvents MoveUpButton As MSForms.CommandButton
Public WithEvents MoveDownButton As MSForms.CommandButton
Public WithEvents TransferButton As MSForms.CommandButton

Public UpDownList As MSForms.ListBox

Public transferFromList As MSForms.ListBox
Public WithEvents TransferToList As MSForms.ListBox

Public OutputText As MSForms.TextBox


Private Sub TransferButton_Click()
     msgbox "Only fires once!!!!!, no matter how often I click the button"
end sub

然后在初始化listboxes的模块中,创建我的类的几个对象(CListMover):

   ' Input box ....
    With GUI_Excel.ListBox_Header_Input
        .MultiSelect = fmMultiSelectExtended
        .ColumnCount = 2
        .columnWidths = "180;50"
    End With


    For i = 1 To lastColumn
        colTitle = Trim(UCase(wsIn.Cells(headerRow, i).value))
        GUI_Excel.ListBox_ColumnHeaderInputFile.AddItem colTitle
        GUI_Excel.ListBox_ColumnHeaderInputFile.List(i - 1, 1) = i

    Next i

    ' Output box ......
    With GUI_Excel.ListBox_ColumnHeaderOutputFile
        .MultiSelect = fmMultiSelectExtended
        .ColumnCount = 4
        .columnWidths = "180;50;100;100"
    End With


    'Move from input to output...
    Set m_clsListMoveIn = New CListMover
    With m_clsListMoveIn
        Set .TransferButton = GUI_Excel.CommandButton_MoveIn
        Set .transferFromList = GUI_Excel.ListBox_ColumnHeaderInputFile
        Set .TransferToList = GUI_Excel.ListBox_ColumnHeaderOutputFile
        .ReverseListBox = True
    End With

    'Move from output to input, i.e delete...
    Set m_clsListMoveOut = New CListMover
    With m_clsListMoveOut
        Set .TransferButton = GUI_Excel.CommandButton_MoveOut
        Set .transferFromList = GUI_Excel.ListBox_Header_Output

        .RemoveItemOnTransfer = True
        .DeleteItemFromList = True

    End With

    ' Move up down ....
    Set m_clsListMoveUpDown = New CListMover
    With m_clsListMoveUpDown
        Set .MoveDownButton = GUI_Excel.CommandButton_MoveDown
        Set .MoveUpButton = GUI_Excel.CommandButton_MoveUp
        Set .UpDownList = GUI_Excel.ListBox_Header_Output
    End With

    GoTo terminate

terminate:
    Exit Sub
End Sub

问题:
该事件似乎只触发一次!因此,我将所有项目放在输入框中,并且可以将项目移动一次,之后它将停止响应我的命令按钮。我需要对按钮本身的事件做些什么?

Private Sub CommandButton_MoveIn_Click()

End Sub

有趣的是,它在excel中可以正常工作,但在文字上却不能。...

0 个答案:

没有答案