XLSfile = "path to file"
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = "DBQ=" & XLSfile & _ ";DRIVER=Microsoft Excel
Driver(*.xls);UID=admin;"
Conn.Open
To query from a default datasheet name you would make a SQL string like
"SELECT * FROM [Sheet1$]".
I need to get the name of the worksheet from the Conn object somehow, so
that my Sheet1 name can be dynamic. Is there a way to get a collection of
the worksheets in an Excel file using this connection object? That way I
could specify something like "Select * From ["&sheetname&"$]".
If I can't use this driver to do the above is there another ADO driver that
I could use?
Thanks,
Nate
Set rsTables = oConn.OpenSchema(adSchemaTables, _
Array(Empty, Empty, Empty, "Table"))
MsgBox rs!TABLE_NAME
--
"nate axtell" <naxtell at progeny dot net> wrote in message news:<ucTEVVGC...@TK2MSFTNGP10.phx.gbl>...
Dim rsSchema, field, line
Set rsSchema = Conn.OpenSchema(20)
rsSchema.MoveFirst
Do While Not rsSchema.EOF
For Each field In rsSchema.Fields
If field <> "" Then
line = line & field & " "
End if
Next
line = line & vbcrlf
rsSchema.MoveNext
Loop
rsSchema.Close
msgbox line
That will display a list of all the sheets in the excel file for me.
Thanks again,
nate