'用 Application.WorksheetFunction.****,
'举个例子如下
'需要引用Microsoft Excel 12.0 Object Library,版本可能不同
Private Sub Command2_Click()
Dim arr() As String
Dim b As Integer
Dim xlsApp As Excel.Application
Dim xlsWorkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Set xlsApp = CreateObject("Excel.Application")
Set xlsWorkbook = xlsApp.Workbooks.Open("D:\test.xlsx") '按路径打开对应excel
Set xlssheet = xlsWorkbook.Worksheets(1)
b = Application.WorksheetFunction.CountA(Range("A:A")) '调用excel现有函数countA
Print "A列共有行数:" & b
Set xlssheet = Nothing
Set xlsWorkbook = Nothing
Set xlsApp = Nothing
End Sub
温馨提示:答案为网友推荐,仅供参考