标题: Subscript out of range怎么解决 [打印本页] 作者: traning 时间: 2010-6-22 11:29 标题: Subscript out of range怎么解决 代码如下想读取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作者: rojer521 时间: 2010-6-22 14:36
数组下标越界,楼主好好检查一下作者: traning 时间: 2010-6-22 22:13
好的谢谢了作者: 43528782 时间: 2011-4-18 20:10
没看明白是为什么...作者: lanchozxd 时间: 2011-4-19 16:39 本帖最后由 lanchozxd 于 2011-4-19 16:40 编辑