’经实际测试,以下代码数据库和Excel之间互相导入导出,完全成功! Private Sub Command1_Click() 'access导出到excel Dim db As New ADODB.Connection Dim sPath As String db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb Persist Security Info=False" sPath = App.Path + "\backup.xls" If Dir(sPath) <> "" Then Kill sPath Else Call db.Execute("select * into [Sheet1$] In '" & sPath & "' 'excel 8.0;' from 表1") MsgBox "导出成功", vbOKOnly, "提示" End If db.Close Set db = Nothing End Sub Private Sub Command2_Click() '从excel导出到 access Dim db As New ADODB.Connection Dim sPath As String db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\Test\db1.mdb;Persist Security Info=False" sPath = App.Path + "\backup.xls" Call db.Execute("select * into Table4 From [Sheet1$] In '" & sPath & "' 'excel 8.0;'") db.Close Set db = Nothing End Sub |
|
来自: 网络摘记 > 《VB-EXCEL知识》