只要你的excel格式规范就可以 private flag as boolean '标记excel文件是否打开过 '打开excel文件 public sub openexcel(byval strname as string) if flag then closeexcel end if set xlsapp = createobject( "excel.application ") set xlsbook = xlsapp.workbooks.open(strname) set xlssheet = xlsbook.activesheet flag = true end sub
'关闭excel文件 public sub closeexcel() if flag then flag = false xlsbook.close xlsapp.quit set xlsapp = nothing set xlsbook = nothing set xlssheet = nothing end if end sub
'取得excel文件的记录集 public function getexcelrs(byval strname as string) as adodb.recordset dim rs as adodb.recordset set rs = new adodb.recordset dim conn as string rs.cursorlocation = aduseclient rs.cursortype = adopendynamic rs.locktype = adlockbatchoptimistic conn = "data provider=msdasql.1;driver=microsoft excel driver (*.xls);dbq= " & strname rs.open "select * from [sheet1$] ", conn set getexcelrs = rs set rs = nothing end function