|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
请参考
- Sub 将工作表数据自动导入ACCESS数据库()
- Dim cnn As Object, SQL$
- If Range("A1").CurrentRegion.Rows.Count = 1 Then Exit Sub '没有数据退出程序
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\发货记录.mdb"
- SQL = "INSERT INTO " & Replace(ActiveSheet.Name, "模板", "") & " SELECT * FROM [Excel 8.0;Database=" _
- & ThisWorkbook.FullName & ";].[" & ActiveSheet.Name & "$" & Range("A1").CurrentRegion.Address(0, 0) & "]"
- cnn.Execute SQL
- MsgBox "数据导入成功。", vbInformation, "数据导入"
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|