| 发表于:2007-07-17 16:33:133楼 得分:0 |
dim excel_app as object dim excel_sheet as object dim db as database dim accesspath as string, accesstable as string dim sql as string dim frm as new frmmessage dim msg as string adosdb.begintrans with dlgcommondialog .dialogtitle = "打开 " .cancelerror = false 'todo: 设置 common dialog 控件的标志和属性 .filter = "excel文件 (*.xls) ¦*.xls " .showopen if len(.filename) = 0 then exit sub end if sfile = .filename end with accesspath = app.path & "\db.mdb " '数据库路径 excelpath = sfile '电子表格路经 accesstable = "db " '数据库内表格 msg = trim(inputbox( "请输入表名,如sheet1或sheet2: ", "工作表 ", "sheet1 ")) ' msg = str(msg) sheet = msg '电子表格内工作表 set db = opendatabase(excelpath, true, false, "excel 8.0 ") '打开电子表格文件 sql = ( "select * into [;database= " & accesspath & "]. " & accesstable & " from [ " & sheet & "$] ") ' sql = ( "select * into [;database= " & accesspath & "]. " & accesstable & " from [ " & sheet & "] ") if sheet = " " then msgbox "您选择的excel表不存在,请重新导入! ", vbinformation, "抱歉! " exit sub end if adosdb.committrans db.EXECute (sql) '将电子表格导入数据库 将上面的程序稍改下就行了. | | |
|