Sub ls()
  Dim Rst As ADODB.Recordset
  Dim Sql As String
  Sql = "Select * From [Sheet1$]"
  Set Rst = ConnectRst(Sql)
  rr = Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))
End Sub
Function ConnectRst(Sql As String) As ADODB.Recordset
    Dim Cnn As New ADODB.Connection
    Dim Rst As New ADODB.Recordset
    Cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
    Rst.Open Sql, Cnn, adOpenStatic
    Set ConnectRst = Rst
End Function
上面程序
Rst.GetRows(5, 2, Rst.Fields(0), Rst.Fields(1))-有两个字段程序不通过
Rst.GetRows(5, 2, Rst.Fields(0))----有一个字段程序通过
问:在于vb GetRows的字段只能是一个字段吗?

解决方案 »

  1.   

    Rst.GetRows(5, 2, Rst.Fields(0)),指定好了是(A5,B2)单元格的值,只能指定一个字段,想实现填充多个字段,就做个循环完成.如:
    for i 1 to 5
       rr = Rst.GetRows(5, i+1, Rst.Fields(i)) 
    next
      

  2.   

    最后一个用字段名数组
    http://msdn.microsoft.com/en-us/library/ms675120(VS.85).aspx
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://feiyun0112.cnblogs.com/
      

  3.   


    Fields 
    Optional. A Variant that represents a single field name or ordinal position, or an array of field names or ordinal position numbers. ADO returns only the data in these fields.an array of field names ,一个数组字段如何写,需要消化理解(Understanding of the need to digest)