Sub GetSheetCount()
Dim oConn As New ADODB.Connection, adoxCat As ADOX.Catalog, strFileName As String
On Error GoTo ErrHandler:
'Put the file you want here
strFileName = "C:my documentsgeneral ledger pivot table.xls"
With oConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties").Value = "Excel 8.0"
.Open strFileName
End With
Set adoxCat = New Catalog
Set adoxCat.ActiveConnection = oConn
MsgBox adoxCat.Tables.Count
Exit Sub
ErrHandler:
MsgBox Err.Description, , "An error occurred"
End Sub