VBA 导入Access

作者: coiisy | 来源:发表于2019-07-04 10:47 被阅读0次

    Sub 将工作表数据自动导入ACCESS数据库()
    Dim cnn As Object, SQLIf 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

    相关文章

      网友评论

        本文标题:VBA 导入Access

        本文链接:https://www.haomeiwen.com/subject/cbllhctx.html