[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] VBS解开Excel工作表密码求助

各位新年好  ,最近将VBA 解开工作表密码 修改为VBS  出现错误  VBS 我刚入门
目的 是将工作簿拖入VBS 就可以解开该工作簿 每一个工作表的 工作表密码
代码 在VBA 上通过的

求教大家
  1. Set oExcel = CreateObject("Excel.Application")
  2. Set oWorkBook = oExcel.Workbooks.Open(strPath)
  3. For Each oSheet In oWorkBook .Sheets
  4.     RemoveShProtect oSheet
  5. Next
  6. oWorkBook.Close False  ‘关闭文件
  7. Set oWorkBook = Nothing
  8. oExcel.Quit
  9. Sub RemoveShProtect(mywst As Worksheet)
  10.     Dim i1 As Integer, i2 As Integer, i3 As Integer
  11.     Dim i4 As Integer, i5 As Integer, i6 As Integer
  12.     Dim i7 As Integer, i8 As Integer, i9 As Integer
  13.     Dim i10 As Integer, i11 As Integer, i12 As Integer
  14.     Dim t As String
  15.     On Error Resume Next
  16.     If mywst.ProtectContents = False Then
  17.         MsgBox mywst.Name & "该工作表没有保护密码!"
  18.         Exit Sub
  19.     End If
  20.     t = Timer
  21.     For i1 = 65 To 66: For i2 = 65 To 66: For i3 = 65 To 66
  22.         For i4 = 65 To 66: For i5 = 65 To 66: For i6 = 65 To 66
  23.             For i7 = 65 To 66: For i8 = 65 To 66: For i9 = 65 To 66
  24.                 For i10 = 65 To 66: For i11 = 65 To 66: For i12 = 32 To 126
  25.                     mywst.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
  26.                     If mywst.ProtectContents = False Then
  27.                         MsgBox "解除工作表保护!用时" & Format(Timer - t, "0.00") & "秒"
  28.                         Exit Sub
  29.                     End If
  30.                     Next: Next: Next: Next: Next: Next
  31.                     Next: Next: Next: Next: Next: Next
  32.                 End Sub
复制代码

回复 1# 闻启学


    多谢,代码运行时候 发生错误

TOP

修改代码

但是最后保存文件发生异常
  1. If WScript.Arguments.Count <> 1 Then
  2.     MsgBox "参数异常"
  3.     WScript.Quit()
  4. End If
  5. strPath = WScript.Arguments(0)
  6. Set oExcel = CreateObject("Excel.Application")
  7. Set oWorkBook = oExcel.Workbooks.Open(strPath)
  8. For Each oSheet In oWorkBook.Sheets
  9. If oSheet.ProtectContents = False Then
  10.         MsgBox oSheet.Name & "该工作表没有保护密码!"
  11.         Exit for
  12.   End If
  13.     t = Timer
  14. On Error Resume Next
  15.     For i1 = 65 To 66: For i2 = 65 To 66: For i3 = 65 To 66
  16.         For i4 = 65 To 66: For i5 = 65 To 66: For i6 = 65 To 66
  17.             For i7 = 65 To 66: For i8 = 65 To 66: For i9 = 65 To 66
  18.                 For i10 = 65 To 66: For i11 = 65 To 66: For i12 = 32 To 126
  19.                     oSheet.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
  20.                     If oSheet.ProtectContents = False Then
  21.                         MsgBox "解除工作表保护!用时" & Format(Timer - t, "0.00") & "秒"
  22.                         Exit for
  23.                     End If
  24.                     Next: Next: Next: Next: Next: Next
  25.                     Next: Next: Next: Next: Next: Next
  26. Next
  27. oWorkBook.Close true
  28. Set oWorkBook = Nothing
  29. oExcel.Quit
复制代码

TOP

  1. If WScript.Arguments.Count <> 1 Then
  2.     MsgBox "参数异常"
  3.     WScript.Quit()
  4. End If
  5. strPath = WScript.Arguments(0)
  6. Set oExcel = CreateObject("Excel.Application")
  7. Set oWorkBook = oExcel.Workbooks.Open(strPath)
  8. For Each oSheet In oWorkBook.Sheets
  9.     RemoveShProtect oSheet
  10. Next
  11. oWorkBook.Close False    '关闭文件
  12. Set oWorkBook = Nothing
  13. oExcel.Quit()
  14. Sub RemoveShProtect(mywst)
  15.     Dim i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, t
  16.     On Error Resume Next
  17.     If mywst.ProtectContents = False Then
  18.         MsgBox mywst.Name & "该工作表没有保护密码!"
  19.         Exit Sub
  20.     End If
  21.     t = Timer()
  22.     For i1 = 65 To 66 : For i2 = 65 To 66 : For i3 = 65 To 66
  23.     For i4 = 65 To 66 : For i5 = 65 To 66 : For i6 = 65 To 66
  24.     For i7 = 65 To 66 : For i8 = 65 To 66 : For i9 = 65 To 66
  25.     For i10 = 65 To 66 : For i11 = 65 To 66 : For i12 = 32 To 126
  26.         mywst.Unprotect Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(i7) & Chr(i8) & Chr(i9) & Chr(i10) & Chr(i11) & Chr(i12)
  27.         If mywst.ProtectContents = False Then
  28.             MsgBox "解除工作表保护!用时" & Format(Timer() - t, "0.00") & "秒"
  29.             Exit Sub
  30.         End If
  31.     Next : Next : Next : Next : Next : Next : Next : Next : Next : Next : Next : Next
  32. End Sub
复制代码

QQ 20147578

TOP

返回列表