Excel VBA读取 ACCESS 数据 连接

随笔2

Sub access_test()

Dim CONN As Object
Dim RST As Object
Dim SQL As String

Sheets("Sheet1").Cells.Clear

Set CONN = CreateObject("adodb.connection")
Set RST = CreateObject("adodb.recordset")

SQL = "select * from 律师函8月分"

CONN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\新建 Microsoft Access 数据库.accdb" & ";ACE OLEDB:Database Password="

 Set RST = CONN.Execute(SQL)

For i = 1 To RST.Fields.Count
    Cells(1, i) = RST.Fields(i - 1).Name
Next


Sheets("Sheet1").[a2].CopyFromRecordset RST
CONN.Close
Set C0NN = Nothing

End Sub

你可能感兴趣的:(Excel VBA读取 ACCESS 数据 连接)