#2
zhulei1332017-06-06 20:51
|
文件夹里有多个excel表格,批处理,得到每个表格的行数,没有加密的表格文件可以一直运行,如何修改遇到加密的表格文件继续运行?
Set fs = CreateObject("scripting.FileSystemObject")
Set excel = CreateObject("excel.application")
Set resultBookSheet = excel.Workbooks.Add().Sheets(1)
excel.visible = true
resultBookSheet.Visible = True
resultBookSheet.activate
i = 1
For Each fileName In fs.GetFolder(CreateObject("WScript.Shell").CurrentDirectory).Files
If Right(fileName, 4) = ".xls" Then
Set book = excel.Workbooks.Open(fileName)
resultBookSheet.Cells(i, 1) = fs.getfileName(fileName)
For Each sheet In book.Sheets
resultBookSheet.Cells(i, 2) = sheet.Name
resultBookSheet.Cells(i, 3) = sheet.UsedRange.Rows.Count + sheet.UsedRange.Row - 1
i = i + 1
Next
book.Close False
Set book = Nothing
End If
Next