|
Function ReadExcel(sFilename,sSheetName) '读取excel文件 ,sFilename文件地址,sSheetName Sheet名称
Dim oRange
Dim arrRange
On Error Resume Next
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Open(sFilename)
Set oRange = oExcel.Worksheets(sSheetName).UsedRange
If Err.Number <>0 Then
ReadExcel = Array("Error")
Exit Function
End If
On Error Goto 0
arrRange = oRange.Value
oExcel.Workbooks.Item(1).Close
Set oRange = Nothing
oExcel.Quit
Set oExcel = Nothing
ReadExcel = arrRange
End Function
'调用方式
'oArray = ReadExcel("D:\work\测试日志\User.xlsx","Sheet1")
'For I = 1 to UBound(oArray )
' For J = 1 to UBound(oArray,1)
' Print oArray(I,J)
' Next
'Next |
|