我想尝试使用 ado 连接和 vba 将 excel 连接到 excel。但问题是它给出了一个错误,找不到可安装的 ISAM。我试图查看其他解决方案,但同样的问题将返回。可能有一个我缺少的activex控件吗?这是我的代码
Dim cN As ADODB.Connection '* Connection String
Dim RS As ADODB.Recordset '* Record Set
Dim sQuery As String '* Query String
Dim i1 As Long
Dim lMaxRow As Long '* Last Row in the Sheet
Dim iRevCol As Integer '*
Dim i3 As Integer
Set cN = New ADODB.Connection
cN.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PC\Desktop\Excel Programming\PlayerDatabase.xlsm;Readonly=False;Extended Properties=Excel 12.0;;HDR=yes;Persist Security Info=False"
cN.ConnectionTimeout = 40
cN.Open
Set RS = New ADODB.Recordset
lMaxRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
sQuery = "Select * From [Player$]"
RS.ActiveConnection = cN
RS.Source = sQuery
RS.Open
If RS.EOF = True And RS.BOF = True Then
MsgBox ("End of File")
End If
If RS.State <> adStateClosed Then
RS.Close
End If
If Not RS Is Nothing Then Set RS = Nothing
If Not cN Is Nothing Then Set cN = Nothing
更新:
现在我将我的连接字符串更改为此
cN.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PC\Desktop\Excel Programming\PlayerDatabase.xlsm;Extended Properties='Excel 12.0 Macro;HDR=YES'"
但它给了我错误无法更新。数据库或对象是只读的。
当我把 readonly=false
cN.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PC\Desktop\Excel Programming\PlayerDatabase.xlsm;ReadOnly=false;Extended Properties='Excel 12.0 Macro;HDR=YES'"
它会给出一个错误,因为找不到可安装的 ISAM :(