Excel VBA列出特定文件中的所有工作表

我想打印一个特定文件夹下的所有excel文件的列表。 除了文件名之外,我还应该能够打印excel文件下所有表格的名称。

下面是我的打印文件名的代码示例如下。 但是,我无法弄清楚如何读取文件下的表名单?

Sub ButtonRun_Excel_Compare_Report_Click() Sheet1.Cells.Clear ShowFolderList ("D:\temp") End Sub Sub ShowFolderList(folderspec) Dim fs, f, f1, fc, s, sFldr Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder(folderspec) Set fc = f.SubFolders For Each f1 In fc If Right(f1, 1) <> "\" Then ShowFolderList f1 & "\" Else ShowFolderList f1 Next Set fc = f.Files Rowcnt = 1 For Each f1 In fc If f1.Name Like "*.xls" Then 'How to loop through the Sheets under exach file? Sheet1.Cells(Rowcnt, 1) = f1.Name 'Sheet1.Cells(Rowcnt, 2) = f1.Path Rowcnt = Rowcnt + 1 'Debug.Print folderspec & f1.Name End If Next End Sub 

感谢帮助。 谢谢

您将不得不打开工作簿并在工作表对象中循环

 Application.Workbooks.Open Filename:=folderspec & f1.Name For i = 1 to ActiveWorkbook.Sheets.Count strFlenme = ActiveWorkbook.FullName strShtNme = ActiveWorkbook.Sheets(i).Name Debug.print strFlenme & " - " & i & " '" & strShtNme & "'" Next