注册 登录
编程论坛 VB.NET论坛

求高手来帮我改一改

zhulei133 发布于 2017-06-06 20:36, 1364 次点击
文件夹里有多个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
3 回复
#2
zhulei1332017-06-06 20:51
没人吗
#3
厨师王德榜2017-06-08 17:14
加密的文件,你是否知道密码,如果知道的话, 改成  excel.Workbooks.Open(fileName,,,,打开密码,修改密码) 即可。
#4
厨师王德榜2017-06-08 17:17
还有一个思路就是用Try ...Cathch ... Finally 捕获错误代码,产生错误代码的,就是打开Excel失败的。
1