|
Dim Conn
Dim rs
Dim i
Dim sql
'On Error Resume Next
xlsFile="D:\........\book.xls" 'EXCEL路径与文件名
Set fso=CreateObject("scripting.filesystemobject")
If fso.FileExists(xlsFile) Then
Set Conn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.Recordset")
strSheetName="sheet1" 'EXCEL表名
Conn.Open "rovider=Microsoft.Jet.OLEDB.4.0ersist Security Info=False;Data Source="&xlsFile&";Extended Properties='Excel 8.0;HDR=Yes'" '连接EXCEL文件
sql = "select * from [" & strSheetName & "$]" 'ooo
rs.Open sql, Conn,3,3
rs.MoveFirst
If RS.BOF=False Then
viewdata=rs.GetRows
'获取二维数组的长度 UBound(<数组>[,<维数>])
For row=0 To UBound(viewdata,2)
For col=0 To UBound(viewdata,1)
STRsql=STRsql&viewdata(col,row)& " "
Next
STRsql=STRsql&vbCrLf
Next
End If
rs.Close '关闭数据集
Conn.Close '关闭对象
MsgBox strsql
Else
openXlsFile="所打开的文件不存在,请检查路径是否正确"
End If |
|