我正在使用Excel 2016,并且已经检查了Microsoft ActiveX Data Object Recordset 6.0 Library
,如我所看到的教程所示。
我的代码如下:
Sub test_connection()
Dim MyConnectionString As String
Dim MyRecordSet As ADODB.Recordset
MyConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source= C:\Users\ACER\Desktop\SunGleam.mdb;" & _
"User ID=Admin;" & _
"Password=test"
Set MyRecordSet = New ADODB.Recordset
MyRecordSet.Open "Select * From JO", MyConnectionString, adOpenForwardOnly
Worksheets("Test").Range("A2").CopyFromRecordset MyRecordSet
End Sub
根据这本书,它说较新的版本称为Recordset Library
,但我想这是错误的,需要选择Microsoft ActiveX Data Objects 6.1 Library
,如较早的文章所示。