VB 将EXCEL数据导入到Access数据库中
1个回答
展开全部
'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 = "" Then
MsgBox "您选择的EXCEL表不存在,请重新导入!", vbInformation, "抱歉!"Exit SubEnd IfIf deltable = 1 Then
With ADOsdb
.Execute "drop table db", , adCmdTextEnd WithEnd IfADOsdb.CommitTrans
db.Execute (sql) '将电子表格导入数据库
ShowMessage "正在导入EXCEL表,请您稍等..."
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询