Excel开发编程
Excel如何读取Access数据
2005-02-04 19:37:29

Public Function daadfa()'必须引用 ado   ---------     Microsoft ActiveX Date Objects X.X Library

Dim conn As New ADODB.Connection, connstr As String, db As String, rs As New ADODB.Recordset, i As Long, rows As Longdb = "C:\adb2.mdb"connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbconn.Open connstrrs.Open "select * from 表1", conn, 1, 3

If rs.EOF And rs.BOF Then    MsgBox "无记录"Else    rows = 1    For i = 0 To rs.Fields.Count - 1        Worksheets("Sheet2").Cells(1, rows).Value = rs.Fields(i).Name    Next i    Do Until rs.EOF        For i = 0 To rs.Fields.Count - 1            Worksheets("Sheet2").Cells(i + 2, rows).Value = rs(i)        Next i    rows = rows + 1    rs.MoveNext    LoopEnd If

End Function