vb怎样调用Excel中的函数
展开全部
'用 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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |