What you have is great! But I will only need the list of
worksheets from each workbook. Can you provide some
assistance on that ???
The subroutine Demo below will take a folder path as an argument and return
a list of all Excel files (along with each file's worksheets) to the Debug
window. To use it, just enter this in the Debug window (or call it from
code):
Demo "C:\" '/ change this to whatever folder you want to use
Sub Demo(rsFolderPath As String)
Dim fso As Object
Dim fil As Object
Dim vWSNames As Variant
Dim v As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
For Each fil In fso.GetFolder(rsFolderPath).Files
If StrComp(fil.Type, "Microsoft Excel " & _
"Worksheet", vbTextCompare) = 0 Then
Debug.Print fil.Path
vWSNames = mvGetWSNames(fil.Path)
For Each v In vWSNames
Debug.Print " " & CStr(v)
Next v
End If
Next fil
Set fso = Nothing
End Sub
Private Function mvGetWSNames(rsWBPath As String) _
As Variant
Dim adCn As Object
Dim axCat As Object
Dim axTab As Object
Dim asSheets() As String
Dim nShtNum As Integer
Set adCn = CreateObject("ADODB.Connection")
Set axCat = CreateObject("ADOX.Catalog")
With adCn
.ConnectionString = "Provider=Microsoft.Jet.OLEDB" & _
".4.0;Data Source=" & rsWBPath & ";Extended " & _
"Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
.CursorLocation = 3
.Open
End With
Set axCat.ActiveConnection = adCn
For Each axTab In axCat.Tables
ReDim Preserve asSheets(0 To nShtNum)
asSheets(nShtNum) = Left$(axTab.Name, _
Len(axTab.Name) - 1)
nShtNum = nShtNum + 1
Next axTab
mvGetWSNames = asSheets
Set axCat = Nothing
adCn.Close
Set adCn = Nothing
End Function
There is no error handling, so you'd probably want to add some in the case
of a bad folder path or some unexpected error.
--
Regards,
Jake Marx
MS MVP - Excel
www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]