Excel VBA简单但复杂,同时初始化Userform

时间:2015-03-31 15:43:28

标签: excel-vba vba excel

实际上我在Excel VBA中制作了这个项目,我想在文件打开时隐藏ThisWorkbook.visible = False然后加载userform。然而,我的项目运行得很棒但是当我隐藏我的thisworkbook然后我得到一个错误,如"对象_global的方法行失败" 上 对于Cmb = 2 To .Cells(Rows.Count,27).End(xlUp).Row

Sub ComboAddItems()
    Dim Lc, Cmb, CmbItm As Integer
    With ThisWorkbook.Worksheets("Tool Work")
        For Cmb = 2 To .Cells(Rows.Count, 27).End(xlUp).Row
            Lc = .Range(.Cells(Cmb, 28), .Cells(Cmb, 28).End(xlToRight)).Count
            For CmbItm = 1 To Lc
                UserForm1.Controls(.Cells(Cmb, 27).Value).AddItem .Cells(Cmb, 27 + CmbItm).Value
            Next CmbItm
        Next Cmb
    End With
End Sub

1 个答案:

答案 0 :(得分:1)

您错过了限定符:

For Cmb = 2 To .Cells(.Rows.Count, 27).End(xlUp).Row

请注意Rows之前的完整停止。