VBA 遍历指定目录下所有Excel文件并读取文件名

Sub GetSheetName()
    Dim Path As String
    Dim File As String
    Dim WB As Workbook
    Dim sht As Worksheet
    
        Application.ScreenUpdating = False
        Path = ThisWorkbook.Path & "/"
        File = Dir(Path & "*.xlsx")
        Do While File <> ""
            Set WB = Workbooks.Open(Path & File)
            For Each sht In WB.Sheets
                MsgBox sht.Name
            Next

            File = Dir
        Loop
        Application.ScreenUpdating = True
End Sub

  

posted @ 2022-06-28 08:45  tec2019  阅读(1006)  评论(0编辑  收藏  举报