继续获取无法在VBA中加载错误(361)

时间:2018-03-19 06:23:06

标签: excel vba excel-vba

这是我列出两个文本框并从一个文本框到另一个文本框中选择数据的代码。以前它工作正常。现在它继续显示"Could not load or unload this object"

我尝试删除option explicit,删除了打开此表单的模块。什么都行不通。我添加了一个按钮单击命令,然后它显示此错误。点击按钮,我只是试图隐藏此表单并显示另一个表单。但在那之后,就会出现这个错误。我删除了那行代码并尝试了。仍然无法正常工作

我的代码:

Private Sub BTN_moveAllLeft_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox2.ListCount - 1
        Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
    Next iCtr

    Me.ListBox2.Clear
End Sub
Private Sub BTN_moveAllRight_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox1.ListCount - 1
        Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
    Next iCtr

    Me.ListBox1.Clear
End Sub
Private Sub BTN_MoveSelectedLeft_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox2.ListCount - 1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
        End If
    Next iCtr

    For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox2.RemoveItem iCtr
        End If
    Next iCtr

End Sub
Private Sub BTN_MoveSelectedRight_Click()

    Dim iCtr As Long

    For iCtr = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
        End If
    Next iCtr

    For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox1.RemoveItem iCtr
        End If
    Next iCtr

End Sub

'Private Sub cancel_Click()
'Unload.Me
'End Sub

'Private Sub cmdOK_Click()
'frmListBoxTest.Hide
' UserForm2.Show
'End Sub


Private Sub UserForm_Initialize()

    Dim iCtr As Long

    With Me.ListBox1

            .AddItem "1"
            .AddItem "B"
            .AddItem "D"
            .AddItem "G"
            .AddItem "A"
            .AddItem "BS"
            .AddItem "MR"
            .AddItem "Ig"
            .AddItem "Eng"
            .AddItem "BE"
            .AddItem "CS"
            .AddItem "PS"
            .AddItem "C"
            .AddItem "TN"
            .AddItem "HC"
            .AddItem "Cy"
            .AddItem "P"
            .AddItem "Dr"
            .AddItem "ER"


    End With



    Me.ListBox1.MultiSelect = fmMultiSelectMulti
    Me.ListBox2.MultiSelect = fmMultiSelectMulti

End Sub

以前有一个名为module 1的模块,其中包含显示此用户表单的代码。

此表单代码中还有Option Explicit。我删除了。

错误图片:

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

它曾经工作过,现在却没有。最有可能的原因是,如果你没有改变任何东西,那就是编译的代码已经损坏了。

Step 1: export all modules and forms from the vb editor. 
Step 2: save the file as an xlsx (thus removing all vb code)
step 3: Open the xlsx and import all the modules and forms
Step 4: recompile the code (debug,compile)
step 5: save as xlsm