我正在尝试此代码以找出最后一行-
msgbox objExcel.ActiveWorkbook.Sheets(1).Range("A" & Rows.Count).EndXL(up).Row
但我不断收到这个错误-
Object required: Rows
尝试
objExcel.ActiveWorkbook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
只是你的 End(xlUp) 部分是错误的
这是你正在尝试的吗?
Dim oXLApp, wb, ws
'~~> Define xlUp
Const xlUp = -4162
Set oXLApp = CreateObject("Excel.Application")
oXLApp.Visible = True
'~~> Open file. Chnage path as applicable
Set wb = oXLApp.Workbooks.Open("C:\Sample.xlsx")
Set ws = wb.Worksheets(1)
With ws
MsgBox .Range("A" & .Rows.Count).End(xlUp).Row
End With
还要注意使用Worksheets
而不是Sheets
查看此链接以获取解释。
这可能有效:
dim last as integer
ActiveCell.SpecialCells(xlLastCell).Select
last = ActiveCell.SpecialCells(xlLastCell).Row