Kirk,
Here is another approach that works on closed workbooks. This function
returns an array of sheet names.
Use like
aSheets = SheetsADOX("C:\Mytest\Book1.xls")
Function SheetsADOX(FileName As String) As Variant
Dim oConn As Object
Dim oCat As Object
Dim oTable As Object
Dim sConnString As String
Dim sFileName As String
Dim sTableName As String
Dim aSheets As Variant
Dim cLength As Integer
Dim iTestPos As Integer
Dim iStartpos As Integer
Dim i As Long
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FileName & ";" & _
"Extended Properties=Excel 8.0;"
Set oConn = CreateObject("ADODB.Connection")
On Error Resume Next
oConn.Open sConnString
If Err.Number <> 0 Then
SheetsADOX = ""
Exit Function
Else
On Error GoTo 0
Set oCat = CreateObject("ADOX.Catalog")
Set oCat.ActiveConnection = oConn
ReDim aSheets(oCat.Tables.Count - 1)
For Each oTable In oCat.Tables
sTableName = oTable.Name
cLength = Len(sTableName)
iTestPos = 0
iStartpos = 1
'Worksheet name with embedded spaces are enclosed by single
quotes
If Left(sTableName, 1) = "'" And Right(sTableName, 1) = "'" Then
iTestPos = 1
iStartpos = 2
End If
'Worksheet names always end in the "$" character
If Mid$(sTableName, cLength - iTestPos, 1) = "$" Then
aSheets(i) = Mid$(sTableName, iStartpos, cLength -
(iStartpos + iTestPos))
i = i + 1
End If
Next oTable
End If
oConn.Close
Set oCat = Nothing
Set oConn = Nothing
SheetsADOX = aSheets
End Function
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
Kirk said:
Is there a way in which to determine the name of the tab(s) (through code)
in a particular spreadsheet with only knowing the spreadsheet name and
location?