|
代码如下想读取excel文件的内容
arrRange = ReadFile("C:\Documents and Settings\XPMUser\Desktop\input.xlsx","Tree")
Msgbox arrRange(3,1)
Function ReadFile(sFileName,sSheetName)
Dim oExcel
Dim oSheet
Dim oRange
Dim arrRange
On Error Resume Next
Set oExcel = CreateObject("Excel.Application")
If err.Number <> 0 Then
MsgBox "cant find Excel" & vbCrLf & _
"make sure Excel file correct", vbCritical
Exit Function
End If
On Error Goto 0
On Error Resume Next
oExcel.Workbooks.Open(sFileName)
If err.Number <> 0 Then
MsgBox "cant iniliaze Excel " & vbCrLf & _
"make sure Exce", vbCritical
Exit Function
End If
On Error Goto 0
Set oSheet = oExcel.Worksheets(sSheetName).UsedRange
Set oRange = oSheet.Range("A1:Z10")
arrRange = oRange.Value
oExcel.WorkBooks.Item(1).Close
oExcel.Quit
Set oExcel = Nothing
Subscript out of range
ReadFile = arrRange
End Function
运行提示Subscript out of range
Subscript out of range
Subscript out of range |
|