Excel—“撤销工作表保护密码”的破解并获取原始密码

版权声明:本文为博主原创文章,如需转载请指明出处。    https://blog.csdn.net/xujiangdong1992/article/details/76549062
在日常工作中,您是否遇到过这样的情况:您用Excel编制的报表、表格、程序等,在单元格中设置了公式、函数等,为了防止其他人修改您的设置或者防止您自己无意中修改,您可能会使用Excel的工作表保护功能,但时间久了保护密码容易忘记,这该怎么办?有时您从网上下载的Excel格式的小程序,您想修改,但是作者加了工作表保护密码,怎么办?您只要按照以下步骤操作,Excel工作表保护密码瞬间即破!
1、打开您需要破解保护密码的Excel文件;
2、依次点击菜单栏上的工具—宏----录制新宏,输入宏名字如:aa;
3、停止录制(这样得到一个空宏);
4、依次点击菜单栏上的工具—宏----宏,选aa,点编辑按钮;
5、删除窗口中的所有字符(只有几个),替换为下面的内容;

 
  1. ----------------------------------------------------------------------------------------

  2. Option Explicit

  3.  
  4. Public Sub AllInternalPasswords()

  5. ' Breaks worksheet and workbook structure passwords. Bob McCormick

  6. ' probably originator of base code algorithm modified for coverage

  7. ' of workbook structure / windows passwords and for multiple passwords

  8. '

  9. ' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1)

  10. ' Modified 2003-Apr-04 by JEM: All msgs to constants, and

  11. ' eliminate one Exit Sub (Version 1.1.1)

  12. ' Reveals hashed passwords NOT original passwords

  13. Const DBLSPACE As String = vbNewLine & vbNewLine

  14. Const AUTHORS As String = DBLSPACE & vbNewLine & _

  15. "Adapted from Bob McCormick base code by" & _

  16. "Norman Harker and JE McGimpsey"

  17. Const HEADER As String = "AllInternalPasswords User Message"

  18. Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04"

  19. Const REPBACK As String = DBLSPACE & "Please report failure " & _

  20. "to the microsoft.public.excel.programming newsgroup."

  21. Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _

  22. "now be free of all password protection, so make sure you:" & _

  23. DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _

  24. DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _

  25. DBLSPACE & "Also, remember that the password was " & _

  26. "put there for a reason. Don't stuff up crucial formulas " & _

  27. "or data." & DBLSPACE & "Access and use of some data " & _

  28. "may be an offense. If in doubt, don't."

  29. Const MSGNOPWORDS1 As String = "There were no passwords on " & _

  30. "sheets, or workbook structure or windows." & AUTHORS & VERSION

  31. Const MSGNOPWORDS2 As String = "There was no protection to " & _

  32. "workbook structure or windows." & DBLSPACE & _

  33. "Proceeding to unprotect sheets." & AUTHORS & VERSION

  34. Const MSGTAKETIME As String = "After pressing OK button this " & _

  35. "will take some time." & DBLSPACE & "Amount of time " & _

  36. "depends on how many different passwords, the " & _

  37. "passwords, and your computer's specification." & DBLSPACE & _

  38. "Just be patient! Make me a coffee!" & AUTHORS & VERSION

  39. Const MSGPWORDFOUND1 As String = "You had a Worksheet " & _

  40. "Structure or Windows Password set." & DBLSPACE & _

  41. "The password found was: " & DBLSPACE & "$$" & DBLSPACE & _

  42. "Note it down for potential future use in other workbooks by " & _

  43. "the same person who set this password." & DBLSPACE & _

  44. "Now to check and clear other passwords." & AUTHORS & VERSION

  45. Const MSGPWORDFOUND2 As String = "You had a Worksheet " & _

  46. "password set." & DBLSPACE & "The password found was: " & _

  47. DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _

  48. "future use in other workbooks by same person who " & _

  49. "set this password." & DBLSPACE & "Now to check and clear " & _

  50. "other passwords." & AUTHORS & VERSION

  51. Const MSGONLYONE As String = "Only structure / windows " & _

  52. "protected with the password that was just found." & _

  53. ALLCLEAR & AUTHORS & VERSION & REPBACK

  54. Dim w1 As Worksheet, w2 As Worksheet

  55. Dim i As Integer, j As Integer, k As Integer, l As Integer

  56. Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer

  57. Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer

  58. Dim PWord1 As String

  59. Dim ShTag As Boolean, WinTag As Boolean

  60.  
  61. Application.ScreenUpdating = False

  62. With ActiveWorkbook

  63. WinTag = .ProtectStructure Or .ProtectWindows

  64. End With

  65. ShTag = False

  66. For Each w1 In Worksheets

  67. ShTag = ShTag Or w1.ProtectContents

  68. Next w1

  69. If Not ShTag And Not WinTag Then

  70. MsgBox MSGNOPWORDS1, vbInformation, HEADER

  71. Exit Sub

  72. End If

  73. MsgBox MSGTAKETIME, vbInformation, HEADER

  74. If Not WinTag Then

  75. MsgBox MSGNOPWORDS2, vbInformation, HEADER

  76. Else

  77. On Error Resume Next

  78. Do 'dummy do loop

  79. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66

  80. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66

  81. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66

  82. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126

  83. With ActiveWorkbook

  84. .Unprotect Chr(i) & Chr(j) & Chr(k) & _

  85. Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _

  86. Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

  87. If .ProtectStructure = False And _

  88. .ProtectWindows = False Then

  89. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _

  90. Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _

  91. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

  92. MsgBox Application.Substitute(MSGPWORDFOUND1, _

  93. "$$", PWord1), vbInformation, HEADER

  94. Exit Do 'Bypass all for...nexts

  95. End If

  96. End With

  97. Next: Next: Next: Next: Next: Next

  98. Next: Next: Next: Next: Next: Next

  99. Loop Until True

  100. On Error GoTo 0

  101. End If

  102. If WinTag And Not ShTag Then

  103. MsgBox MSGONLYONE, vbInformation, HEADER

  104. Exit Sub

  105. End If

  106. On Error Resume Next

  107. For Each w1 In Worksheets

  108. 'Attempt clearance with PWord1

  109. w1.Unprotect PWord1

  110. Next w1

  111. On Error GoTo 0

  112. ShTag = False

  113. For Each w1 In Worksheets

  114. 'Checks for all clear ShTag triggered to 1 if not.

  115. ShTag = ShTag Or w1.ProtectContents

  116. Next w1

  117. If ShTag Then

  118. For Each w1 In Worksheets

  119. With w1

  120. If .ProtectContents Then

  121. On Error Resume Next

  122. Do 'Dummy do loop

  123. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66

  124. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66

  125. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66

  126. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126

  127. .Unprotect Chr(i) & Chr(j) & Chr(k) & _

  128. Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _

  129. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

  130. If Not .ProtectContents Then

  131. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _

  132. Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _

  133. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)

  134. MsgBox Application.Substitute(MSGPWORDFOUND2, _

  135. "$$", PWord1), vbInformation, HEADER

  136. 'leverage finding Pword by trying on other sheets

  137. For Each w2 In Worksheets

  138. w2.Unprotect PWord1

  139. Next w2

  140. Exit Do 'Bypass all for...nexts

  141. End If

  142. Next: Next: Next: Next: Next: Next

  143. Next: Next: Next: Next: Next: Next

  144. Loop Until True

  145. On Error GoTo 0

  146. End If

  147. End With

  148. Next w1

  149. End If

  150. MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER

  151. End Sub

  152. -----------------------------------------------------------------------------------------

  153. ---------------------

复制到横线以上
6、关闭编辑窗口;
7、依次点击菜单栏上的工具—宏-----宏,选AllInternalPasswords,运行,确定两次;
等一会,就会出现以下对话框:这就是Excel密码对应的原始密码(此密码和原先设置的密码都能打开此文档。如果是别人的文档,你又想恢复密码设置,就可以用此密码进行保护,他就能用他设置的密码打开,你可以试试,很有趣的。字母一定要大写):
--------------------- 
作者:梦里梦见醒不来丶 
来源:CSDN 
原文:https://blog.csdn.net/xujiangdong1992/article/details/76549062 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值