Re: List of worksheets in the folder
I have uploaded two pictures in post #5 (untitled.jpg and untitled2.jpg). The first one is a warning about macro and if I click OK that I can see the second picture "Run time error". On the second warning the debug button is not active. Sorry but not sure what do you mean that is not the picture you saw last night.
Anyway I have tried to modify the macro by my own, but I have just basic knowledge about this and I cannot understand how this macro works. I think that is nothing wrong with your code, just when it open the workbooks it also starts the macros from Workbook_Open() section. However the macro I have posted check the worksheet names in other way (without opening the file) so that is way I do not see the warning messages.
If it possible to modify the initial macro I would be very grateful. Below is just the code from the file I have uploaded in the first post.
Option Explicit 'http://www.ozgrid.com/forum/showthread.php?t=166870
Sub ertert()
Dim Fldr$, f$, j&, fileNames$(), nm$, sheetNames()
Fldr = ThisWorkbook.Path: If Fldr = "" Then Exit Sub ':)
Application.ScreenUpdating = False
ActiveSheet.UsedRange.Offset(1).ClearContents
If Right(Fldr, 1) <> "\" Then Fldr = Fldr & "\"
nm = ThisWorkbook.Name
On Error GoTo Metka
f = Dir(Fldr & "*.xls*", vbNormal)
Do While f <> ""
If f <> nm Then
ReDim Preserve fileNames(j): fileNames(j) = f: j = j + 1
sheetNames() = ListSpreadsheets(Fldr & f)
Cells(j + 1, 2).Resize(, UBound(sheetNames)).Value = sheetNames()
End If
f = Dir()
Loop
Range("A2").Resize(UBound(fileNames) + 1).Value = WorksheetFunction.Transpose(fileNames)
Application.ScreenUpdating = True
Metka:
End Sub
'Based on:
'http://www.planetaexcel.ru/forum.php?thread_id=13569
'http://www.rondebruin.nl/ado.htm
'ZVI:2010-02-16 http://www.planetaexcel.ru/forum.php?thread_id=13569
'http://www.excelforum.com/excel-programming/798233-finding-sheet-names-in-a-closed-file.html
'http://www.vb-helper.com/howto_ado_list_tables_fields.html
'and http://support.microsoft.com/kb/257819
'********************************************************************
'***** Set Reference to Microsoft ActiveX Data Objects 2.8 Library
'********************************************************************
Function ListSpreadsheets(ByVal FileName As String)
Dim sPrv$, sConStr$, y(), i&
If Val(Application.Version) < 12 Then
sPrv = "Microsoft.Jet.OLEDB.4.0": sConStr = "Data Source=" & FileName & ";Extended Properties=Excel 8.0;"
Else
sPrv = "Microsoft.ACE.OLEDB.12.0": sConStr = "Data Source=" & FileName & ";Extended Properties=Excel 12.0;"
End If
With New ADODB.Connection
.Provider = sPrv: .ConnectionString = sConStr: .CursorLocation = adUseClient: .Open
' With .OpenSchema(adSchemaTables)
With .OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
ReDim y(1 To CLng(.RecordCount))
For i = 1 To UBound(y)
y(i) = Replace(.Fields("TABLE_NAME").Value, "$", ""): .MoveNext
Next i: .Close
End With: .Close
End With
ListSpreadsheets = y()
End Function
Display More