"<应用程序定义或对象定义的错误>错误1004"

Har*_*orn 1 excel vba excel-vba

我有一个简单的for-next来填充用户表单上的一些标签,但无法弄清楚为什么一直得到"错误1004"当我输入Contr.Caption时,.Caption函数丢失了?

Dim Control_Name As String
Dim DSlot As Long
Dim DLName As Long
Dim Contr As Control

With Worksheets("apartments").Range("depositslot")
    DSlot = .Find("Slot").Row + 1
    DLName = .Find("Last").Column
End With

For Each Contr In Layout.Controls
    If TypeName(Contr) = "Label" Then
        Control_Name = Mid(Contr.Name, 1, 6)
            If Control_Name = "LBName" Then
                Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value
                DSlot = DSlot + 1
            End If
    End If
Next
Run Code Online (Sandbox Code Playgroud)

Yow*_*E3K 5

你的话说:

Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value
Run Code Online (Sandbox Code Playgroud)

应该

Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value
Run Code Online (Sandbox Code Playgroud)

Range属性不接受两个类型的参数Long.