在 excel 2007 vba 中找不到可安装的 ISAM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18013143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:32:06  来源:igfitidea点击:

Could not find installable ISAM in excel 2007 vba

vbaexcel-2007

提问by user2328935

i want to try connecting excel to excel using ado connection and vba. but the problem is it give's an error could not find installable ISAM. i tried to look at other solution but same issue will return. may be there's a activex control that im missing? here's my code

我想尝试使用 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

UPDATE:

更新:

now i change my connectionstring to this

现在我将我的连接字符串更改为此

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'"

but it gives me error Cannot update. Database or object is readonly.

但它给了我错误无法更新。数据库或对象是只读的。

when i put readonly=false

当我把 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'"

it will give an error as could not find installable ISAM :(

它会给出一个错误,因为找不到可安装的 ISAM :(

回答by Kazimierz Jawor

I don't know what is inside your XLSMfile you retrieve data from but you connection string should be as simple as possible. This is working for me (but I didn't check for read-only parameter):

我不知道您XLSM从中检索数据的文件中有什么内容,但您的连接字符串应该尽可能简单。这对我有用(但我没有检查只读参数):

"Provider=Microsoft.ACE.OLEDB.12.0;" & _
           "Data Source=C:\Users\Dane\BazaDanych.xlsm;" & _
           "Extended Properties=Excel 12.0 Macro"

回答by user4049619

Solved it as follows:

解决了如下:

string ConeectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtFlp.Text + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"");
OleDbConnection oconn = new OleDbConnection(ConeectionString);