Dim adocn As ADODB.Connection
  Dim Cnstr As String
  Cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\qq\1231.mdb"
  Set adocn = New ADODB.Connection
  adocn.ConnectionString = Cnstr
  adocn.Open
  adocn.Execute " insert into [excel 8.0;database=c:\qq\1123.xls].[sheet1] select * from aaa"
  Set adocn = Nothing
c:\qq\1123.xls].[sheet1导入1231.mdb aaa错在哪里? 

解决方案 »

  1.   

    ’经实际测试,以下代码数据库和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 SubPrivate Sub Command2_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"
        Call db.Execute("select * into Table4 From Sheet1  In '" & sPath & "' 'excel 8.0;'")
            
        db.Close
        Set db = Nothing
    End Sub
      

  2.   

    worldy  上部段程序OK
    下半段'execl导出到access

    Call db.Execute("select * into Table4 From Sheet1 In '" & sPath & "' 'excel 8.0;'")
    好像出错。提示“实时错误”424“要求对象”
      

  3.   

    记得测试通过的,怎么又不行了,呵呵
    改了一下,测试没问题:Private Sub Command5_Click()
        '从excel导出到access
        Dim db As New ADODB.Connection
        Dim sPath As String
        
        
        sPath = App.Path + "\测试数据\"
        
        db.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath & "\db1.mdb;Persist Security Info=False"
        Call db.Execute("select * into Table4 From [Sheet1$] In '" & sPath & "\Book2.xls' 'excel 8.0;'")
            
        db.Close
        Set db = Nothing
    End Sub