簡體   English   中英

“ <Application-defined or object-defined error> 錯誤1004”

[英]“<Application-defined or object-defined error> Error 1004”

我有一個簡單的for-next來填充用戶窗體上的一些標簽,但無法弄清楚為什么在輸入Contr.Caption時會不斷出現“錯誤1004”的問題。

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

您的行說:

Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value

應該

Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value

Range屬性不接受Long類型的兩個參數。

嘗試通過“單元格”更改“范圍”對象,因為您具有“行,列”的引用。 您應該具有以下內容:

Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM