View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default read sheetnames with ADO

This seems to do the trick. Test it though.

''Needs 2 ADO references
'' - ActiveX Data Objects
'' - ADO Ext for DDL and Security

Sub Demo()
ReadSheetNames "c:\Filename.xls"
End Sub

''Displays sheets names in a closed workbook
Sub ReadSheetNames(TheCompleteFilePath As String)
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table

cnn.Open "Provider=MSDASQL.1;Data Source=" _
& "Excel Files;Initial Catalog=" & TheCompleteFilePath
cat.ActiveConnection = cnn
For Each tbl In cat.Tables
If tbl.Type = "SYSTEM TABLE" Then ''Type "TABLE" seems to return
multicell ranges
Debug.Print Left$(tbl.Name, Len(tbl.Name) - 1)
End If
Next tbl

Set cat = Nothing
cnn.Close
Set cnn = Nothing
End Sub

--
Jim Rech
Excel MVP
"farmer" wrote in message
...
| Hi,
|
| I was wondering wether it's possible to use ADO for retrieving
| sheetnames from an excel workbook.
|
| Does anyone know where to find examples?
|
| I'm using VB 6.0 and excel 2003
|
| Help appreciated,
|
|
| Farmer
|
|