’經(jīng)實(shí)際測(cè)試,以下代碼數(shù)據(jù)庫(kù)和Excel之間互相導(dǎo)入導(dǎo)出,,完全成功,! Private Sub Command1_Click() 'access導(dǎo)出到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 "導(dǎo)出成功", vbOKOnly, "提示" End If db.Close Set db = Nothing End Sub Private Sub Command2_Click() '從excel導(dǎo)出到 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 |
|