"用 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
"用 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