Advertisement
Java_Volume1 Databases/ Data Access/ DAO/ ADO #89012

Read Excel as Recordset

An alternative method of reading an MS Excel Spreadsheet.

AI

Podsumowanie AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kod źródłowy
original-source
Dim cn As ADODB.Connection
Dim rsADO As New ADODB.Recordset
Dim strSQL As String
Dim strPath as string

Set cn = New ADODB.Connection
strPath = '[ADD FULL PATH AND FILE NAME]
With cn
  .Provider = "MSDASQL"
  .ConnectionString = "Driver={Microsoft Excel Driver (*.xls)};" & _
  "DBQ=" & strPath & " ; ReadOnly=false;MaxScanRows= 0;"
  .Open
End With
  ' Specify Sheet Name and Cell Range 
  strSQL = "SELECT * FROM [Sheet1$A1:Z10]"
  rsADO.Open strSQL, cn
  Do while not rs.EOF
  	' Add code here to work with recordset
  rsADO.MoveNext
  Loop
Set cn = Nothing
Set rsADO = Nothing
Oryginalne komentarze (3)
Odzyskane z Wayback Machine