VBA 传递表单对象时类型不匹配

VBA Type mismatch when passing form objects

作为新手(放轻松 :-),我在从函数传递信息时遇到类型不匹配问题。

' Generate Data Sub Function
Sub Send_listbox_list_to_function()

' Function to Create and populate the class
' -> Require's the listbox and the directory location

If Right(frmMain.txtDIR, 1) = "\" Then
    Call Create_Class(frmMain.lstDIR, frmMain.txtDIR.Value)
Else
    Call Create_Class(frmMain.lstDIR, frmMain.txtDIR.Value + "\")
End If

End Sub

这是我试图传递信息的函数。

Sub Create_Class(ByRef lstbox As ListBox, ByVal loc As String)

' Generic Checksheet
Dim checksheet As cls_DR

End Sub

这在 VBA 中可行吗?我担心它在使用表格时会出现时间错误。我无法理解。帮忙?

您的参数被声明为错误的 Listbox 类型(Excel 库中也有一个)。你需要使用这个:

Sub Create_Class(ByRef lstbox As MSForms.ListBox, ByVal loc As String)