Sub ttt()
Dim conn
Set conn = CreateObject("adodb.connection")
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Test.mdb"
conn.Open
conn.Execute "insert into 表名(A,B,C) select * from [Excel 8.0;DataBase=" & ActiveWorkbook.FullName & "].[表1$]"
conn.Execute "insert into 表名(B,D,E) select * from [Excel 8.0;DataBase=" & ActiveWorkbook.FullName & "].[表2$]"
conn.Execute "insert into 表名(A,D) select * from [Excel 8.0;DataBase=" & ActiveWorkbook.FullName & "].[表3$]"
conn.Close
Set conn = Nothing
End Sub
以上代码写在excel中,
E:\Test.mdb为access数据库完整路径,“表名”为access目标表名
代码执行3次sql命令将3个表导入
追问谢谢,看了你的代码我已经有思路了
先用字典提取所有分表的不重复字段
再创建表,写入所有字段
然后遍历每一个工作表,分别提取各表的字段,写入SQL语句