Robert,
Here is an example that reads a sheet and displays the column names
Sub ExcelSheet()
Dim oConn As Object
Dim oRS As Object
Dim sFilename As String
Dim sConnect As String
Dim sSQL As String
Dim i As Long
sFilename = "c:\Mytest\Volker1.xls"
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFilename & ";" & _
"Extended Properties=Excel 8.0;"
sSQL = "SELECT * FROM [Sheet1$]"
Set oRS = CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM [Sales$A1:E89]"
Set oRS = New ADODB.Recordset
oRS.Open sSQL, sConnect, 0, 1, 1
' Check to make sure we received data.
'>>>>>>>>>>>> THIS BIT
For i = 0 To oRS.Fields.Count - 1
MsgBox oRS.Fields(i).Name
Next i
If Not oRS.EOF Then
Sheet1.Range("A1").CopyFromRecordset oRS
Else
MsgBox "No records returned.", vbCritical
End If
' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
Robert Paresi said:
Hello,
Can someone please tell me how to retreive the column NAMES from an Excel
spreadsheet. I can get the data, but I need to know the column names?
Thank you!