Public cnn As New ADODB.Connection
Public Adodc1 As New ADODB.Recordset
Private Sub Command5_Click() Dim ex  As New Excel.Application
Dim exwbook  As New Excel.Workbook
Dim exsheet  As New Excel.Worksheetcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties='Excel 9.0;HDR=Yes'"
cnn.CursorLocation = adUseClient
cnn.Open
Adodc1.Open "select * from [Sheet1]", cnn, adOpenKeyset, adLockOptimistic
Set Me.DataGrid1.DataSource = Adodc1End Sub
我想通过ADO连接EXCEL表,对EXCEL表内的数据进行数据查询操作
执行上面的代码出现错误提示
“找不到可安装的ISAM“
我的代码有什么问题吗???

解决方案 »

  1.   

    Provider=Microsoft.Jet.OLEDB.4.0;
     這個地要換成excel 的driver,你自已找一下,我也記不請是怎麼寫的了
      

  2.   

    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties='Excel 9.0;HDR=Yes'"
    //去掉单引号
    Adodc1.Open "select * from [Sheet1]", cnn, adOpenKeyset, adLockOptimistic
    //sheet1改为sheet1$
      

  3.   

    Public cnn As New ADODB.Connection
    Public Adodc1 As New ADODB.Recordset
    Private Sub Command5_Click() Dim ex  As New Excel.Application
    Dim exwbook  As New Excel.Workbook
    Dim exsheet  As New Excel.Worksheetcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source= c:\yj\1.xls;Extended Properties=Excel 9.0;HDR=Yes"
    cnn.CursorLocation = adUseClient
    cnn.Open
    Adodc1.Open "select * from [Sheet1$]", cnn, adOpenKeyset, adLockOptimistic
    Set Me.DataGrid1.DataSource = Adodc1End Sub是这样改嘛??
    还是不行呀,去掉那个单引号???
      

  4.   

    查一下书吧
       应该是“Provider=Microsoft.Jet.OLEDB.4.0;”出了点问题
      

  5.   

    从“工程”菜单中选择“引用”栏;选择Microsoft Excel 9.0 Object Library (Excel2000),然后选择“确定”。表示在工程中要引用Excel类型库。Dim xlApp As Excel.Application '定义Excel类
    Dim xlBook As Excel.Workbook '定义工作薄类
    Dim XlSheet As Excel.Worksheet '定义工作表类
    Private Sub Command1_Click() '打开Excel过程
    If Dir("D:\temp\excel.bz")= “”Then '判断Excel是否打开
    Set xlApp = CreateObject("Excel.Application") '创建Excel应用类
    xlApp.Visible = True '设置Excel可见
    Set xlBook = xlApp.Workbooks.Open("D:\temp\bb.xls") '打开Excel工作薄
    Set xlSheet = xlBook.Worksheets("Sheet1") '打开Excel工作表
    xlSheet.Activate '激活工作表
    xlSheet.Cells(1,1) = “abc” '给单元格1行驶列赋值
      

  6.   

    我来帮忙,引用:ADO2.6
    Public Sub main()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\book1.xls;Persist Security Info=False;User ID=Admin;Password=;Extended properties=Excel 5.0"
    cn.CursorLocation = adUseClient
    cn.Open
    rs.Open "SELECT * FROM [Sheet1$]", cn, adOpenDynamic, adLockBatchOptimistic
    MsgBox rs.RecordCount
    rs.MoveFirst
    Do While rs.EOF <> True
        MsgBox rs.Fields.Item(0).Name
        MsgBox rs.Fields.Item(0).Value
    rs.MoveNext
    Loop
    If rs.State <> adStateClosed Then rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    End Sub
      

  7.   

    Private Sub Form_Load()
    Adodc1.ConnectionString = "DBQ=E:\a.xls;DefaultDir=E:\;Driver={Driver do Microsoft Excel(*.xls)};DriverId=790;FIL=excel 8.0;FILEDSN=E:\a.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;ReadOnly=1;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
    Adodc1.RecordSource = "select * from [Sheet1$]"
    Adodc1.Refresh
    Set DataGrid1.DataSource = Adodc1End Sub
    试试这个,本机调试成功了。
      

  8.   

    你的机器上 Excel 的版本?或者说 Excel 9.0 是否存在?
      

  9.   

    EXCEL换成5.0 8.0 11.0 都行