发布网友 发布时间:2022-04-08 18:49
共1个回答
热心网友 时间:2022-04-08 20:18
'ToDo: 设置 common dialog 控件的标志和属性.Filter = "Excel文件 (*.xls) |*.xls".ShowOpenIf Len(.FileName) = 0 ThenExit SubEnd Ifsfile = .FileNameEnd WithAccessPath = lcspath & "\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 = "" ThenMsgBox "您选择的EXCEL表不存在,请重新导入!", vbInformation, "抱歉!"Exit SubEnd IfIf deltable = 1 ThenWith ADOsdb.Execute "drop table db", , adCmdTextEnd WithEnd IfADOsdb.CommitTransdb.Execute (sql) '将电子表格导入数据库ShowMessage "正在导入EXCEL表,请您稍等..."