Sub Test() Dim fso As New FileSystemObject Dim fFile As Object Dim strFileName As String Dim strFile As String Dim intRow As Integer Dim fromPath As String Dim xlBook As New Excel.Workbook Dim xlSheet As New Excel.Worksheet fromPath = "C:\" '指定文件夹 If Right(fromPath, 1) <> "\" Then fromPath = fromPath & "\" For Each fFile In fso.GetFolder(fromPath).Files If UCase(Right(fFile.Name, 3)) = "XLS" Then strFileName = fFile.Name Set xlBook = Workbooks.Open(fromPath & fFile.Name) Set xlSheet = xlBook.Sheets(1) intRow = xlSheet.UsedRange.Rows.Count strFileInfo = strFileName & "包含" & intRow & "行" strFile = strFile & "'" & strFileInfo xlBook.Close Set xlBook = Nothing End If Next MsgBox strFile End Sub |