Open the Excel worksheet, create a recordset with the data in the sheet, and then print it in the Immediate window. : Excel Recordset « Excel « VBA / Excel / Access / Word






Open the Excel worksheet, create a recordset with the data in the sheet, and then print it in the Immediate window.

 
Sub openWorksheet()
   Dim myConnection As New ADODB.Connection
   Dim myRecordset As ADODB.Recordset
   
   myConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=C:\myCustomers.xls;" & _
      "Extended Properties=Excel 8.0;"

      Set myRecordset = New ADODB.Recordset
      myRecordset.Open "customers", myConnection, , , adCmdTable

      Do Until myRecordset.EOF
         Debug.Print myRecordset("txtNumber"), myRecordset("txtBookPurchased")
         myRecordset.MoveNext
      Loop
End Sub

 








Related examples in the same category

1.Linking an Excel Spreadsheet