[英]Excel VBA list all sheets in a specific file
我正在嘗試在特定文件夾下打印所有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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.