无论我尝试什么,都会始终显示对象错误。我在VBA方面经验不足。
它似乎是在给“ lastrow”变量赋值时。
Const sFILE_PATH As String = "C:\Users\Downloads\"
Const sEXTENSION As String = ".xlsm"
Dim lastrow As Long
Dim lastrow_Offset As Long: lastrow_Offset = ThisWorkbook.Sheets("Test").Cells(Rows.Count, "h").End(xlUp).Row
Dim wbk As Workbook
Dim sFileName As String
sFileName = "2018-12"
Set wbk = Workbooks.Open(sFILE_PATH & sFileName & sEXTENSION)
Set lastrow = wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row
答案 0 :(得分:1)
您已经定义了Dim lastrow As Long
,因此它不是必须为Set
的对象。这是一个需要分配的变量
lastrow = wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row
我尚未针对您的隐式工作簿结构对此进行过测试,但假设wbk.Sheets("Acc").Cells(Rows.Count, "C").End(xlUp).Row
的评估结果为Long