Retrieve Xls file data
上一篇 /
下一篇 2008-06-03 13:58:47
/ 个人分类:QTP脚本
'Returns a two dimentional array with the excel data
Function GetExcelData(sFileName, sSheetName)
Dim oExcel 'The excel's COM object
Dim arrRange 'The retrieved data
On Error Resume Next
Set ōExcel = CreateObject("Excel.Application")
If err.Number <> 0 Then
MsgBox "Can't Initiate excel." & vbCrLf & _
"This operation requires MS excel to be installed.", vbCritical
Exit Function
End If
On Error Goto 0
On Error Resume Next
oExcel.Workbooks.Open(sFileName)
If err.Number <> 0 Then
MsgBox "Can't load excel file." & vbCrLf & _
"Make sure the file name is correct", vbCritical
Exit Function
End If
On Error Goto 0
'Open the sheet and extract the data
Set ōSheet = oExcel.Worksheets(sSheetName).UsedRange
Set ōRange = oSheet.Range("A1:Z1000")
'Cast excel data into a two-dimentional array
arrRange = oRange.Value
oExcel.WorkBooks.Item(1).Close
oExcel.Quit
Set ōExcel = Nothing
GetExcelData = arrRange
End Function
收藏
举报
TAG:
QTP脚本