'移除VBA编码保护 Sub MoveProtect() Dim FileName AsString FileName = Application.GetOpenFilename("Excel文件(*.xls & *.xla),*.xls;*.xla", , "VBA破解") If FileName = CStr(False) Then ExitSub Else VBAPassword FileName, False EndIf EndSub '设置VBA编码保护 Sub SetProtect() Dim FileName AsString FileName = Application.GetOpenFilename("Excel文件(*.xls & *.xla),*.xls;*.xla", , "VBA破解") If FileName = CStr(False) Then ExitSub Else VBAPassword FileName, True EndIf EndSub PrivateFunction VBAPassword(FileName AsString, Optional Protect AsBoolean = False) If Dir(FileName) = ""Then ExitFunction Else FileCopy FileName, FileName & ".bak" EndIf Dim GetData AsString * 5 Open FileName ForBinaryAs #1 Dim CMGs AsLong Dim DPBo AsLong For i = 1To LOF(1) Get #1, i, GetData If GetData = "CMG="""Then CMGs = i If GetData = "[Host"Then DPBo = i - 2: ExitFor Next If CMGs = 0Then MsgBox "请先对VBA编码设置一个保护密码...", 32, "提示" ExitFunction EndIf If Protect = FalseThen Dim St AsString * 2 Dim s20 AsString * 1 '取得一个0D0A十六进制字串 Get #1, CMGs - 2, St '取得一个20十六制字串 Get #1, DPBo + 16, s20 '替换加密部份机码 For i = CMGs To DPBo Step2 Put #1, i, St Next '加入不配对符号 If (DPBo - CMGs) Mod2 <> 0Then Put #1, DPBo + 1, s20 EndIf MsgBox "文件解密成功......", 32, "提示" Else Dim MMs AsString * 5 MMs = "DPB=""" Put #1, CMGs, MMs MsgBox "对文件特殊加密成功......", 32, "提示" EndIf Close #1 EndFunction
Sheet保护密码
VBA脚本
xlsx:打开VBA编辑器执行代码
1 2 3 4 5 6 7
Sub pj() Dim sht As Worksheet ForEach sht In Worksheets sht.Protect AllowFiltering:=True sht.Unprotect Next EndSub
PublicSub AllInternalPasswords() ' Breaks worksheet and workbook structure passwords. Bob McCormick ' probably originator of base code algorithm modified for coverage ' of workbook structure / windows passwords and for multiple passwords ' ' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1) ' Modified 2003-Apr-04 by JEM: All msgs to constants, and ' eliminate one Exit Sub (Version 1.1.1) ' Reveals hashed passwords NOT original passwords Const DBLSPACE AsString = vbNewLine & vbNewLine Const AUTHORS AsString = DBLSPACE & vbNewLine & _ "Adapted from Bob McCormick base code by" & _ "Norman Harker and JE McGimpsey" Const HEADER AsString = "AllInternalPasswords User Message" Const VERSION AsString = DBLSPACE & "Version 1.1.1 2003-Apr-04" Const REPBACK AsString = DBLSPACE & "Please report failure " & _ "to the microsoft.public.excel.programming newsgroup." Const ALLCLEAR AsString = DBLSPACE & "The workbook should " & _ "now be free of all password protection, so make sure you:" & _ DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _ DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _ DBLSPACE & "Also, remember that the password was " & _ "put there for a reason. Don't stuff up crucial formulas " & _ "or data." & DBLSPACE & "Access and use of some data " & _ "may be an offense. If in doubt, don't." Const MSGNOPWORDS1 AsString = "There were no passwords on " & _ "sheets, or workbook structure or windows." & AUTHORS & VERSION Const MSGNOPWORDS2 AsString = "There was no protection to " & _ "workbook structure or windows." & DBLSPACE & _ "Proceeding to unprotect sheets." & AUTHORS & VERSION Const MSGTAKETIME AsString = "After pressing OK button this " & _ "will take some time." & DBLSPACE & "Amount of time " & _ "depends on how many different passwords, the " & _ "passwords, and your computer's specification." & DBLSPACE & _ "Just be patient! Make me a coffee!" & AUTHORS & VERSION Const MSGPWORDFOUND1 AsString = "You had a Worksheet " & _ "Structure or Windows Password set." & DBLSPACE & _ "The password found was: " & DBLSPACE & "$$" & DBLSPACE & _ "Note it down for potential future use in other workbooks by " & _ "the same person who set this password." & DBLSPACE & _ "Now to check and clear other passwords." & AUTHORS & VERSION Const MSGPWORDFOUND2 AsString = "You had a Worksheet " & _ "password set." & DBLSPACE & "The password found was: " & _ DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _ "future use in other workbooks by same person who " & _ "set this password." & DBLSPACE & "Now to check and clear " & _ "other passwords." & AUTHORS & VERSION Const MSGONLYONE AsString = "Only structure / windows " & _ "protected with the password that was just found." & _ ALLCLEAR & AUTHORS & VERSION & REPBACK Dim w1 As Worksheet, w2 As Worksheet Dim i AsInteger, j AsInteger, k AsInteger, l AsInteger Dim m AsInteger, n AsInteger, i1 AsInteger, i2 AsInteger Dim i3 AsInteger, i4 AsInteger, i5 AsInteger, i6 AsInteger Dim PWord1 AsString Dim ShTag AsBoolean, WinTag AsBoolean
Application.ScreenUpdating = False With ActiveWorkbook WinTag = .ProtectStructure Or .ProtectWindows EndWith ShTag = False ForEach w1 In Worksheets ShTag = ShTag Or w1.ProtectContents Next w1 IfNot ShTag AndNot WinTag Then MsgBox MSGNOPWORDS1, vbInformation, HEADER ExitSub EndIf MsgBox MSGTAKETIME, vbInformation, HEADER IfNot WinTag Then MsgBox MSGNOPWORDS2, vbInformation, HEADER Else OnErrorResumeNext Do'dummy do loop For i = 65To66: For j = 65To66: For k = 65To66 For l = 65To66: For m = 65To66: For i1 = 65To66 For i2 = 65To66: For i3 = 65To66: For i4 = 65To66 For i5 = 65To66: For i6 = 65To66: For n = 32To126 With ActiveWorkbook .Unprotect Chr(i) & Chr(j) & Chr(k) & _ Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _ Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n) If .ProtectStructure = FalseAnd _ .ProtectWindows = FalseThen PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _ Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _ Chr(i4) & Chr(i5) & Chr(i6) & Chr(n) MsgBox Application.Substitute(MSGPWORDFOUND1, _ "$$", PWord1), vbInformation, HEADER ExitDo'Bypass all for...nexts EndIf EndWith Next:Next: Next: Next: Next: Next Next:Next: Next: Next: Next: Next LoopUntilTrue OnErrorGoTo0 EndIf If WinTag AndNot ShTag Then MsgBox MSGONLYONE, vbInformation, HEADER ExitSub EndIf OnErrorResumeNext ForEach w1 In Worksheets 'Attempt clearance with PWord1 w1.Unprotect PWord1 Next w1 OnErrorGoTo0 ShTag = False ForEach w1 In Worksheets 'Checks for all clear ShTag triggered to 1 if not. ShTag = ShTag Or w1.ProtectContents Next w1 If ShTag Then ForEach w1 In Worksheets With w1 If .ProtectContents Then OnErrorResumeNext Do'Dummy do loop For i = 65To66: For j = 65To66: For k = 65To66 For l = 65To66: For m = 65To66: For i1 = 65To66 For i2 = 65To66: For i3 = 65To66: For i4 = 65To66 For i5 = 65To66: For i6 = 65To66: For n = 32To126 .Unprotect Chr(i) & Chr(j) & Chr(k) & _ Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _ Chr(i4) & Chr(i5) & Chr(i6) & Chr(n) IfNot .ProtectContents Then PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _ Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _ Chr(i4) & Chr(i5) & Chr(i6) & Chr(n) MsgBox Application.Substitute(MSGPWORDFOUND2, _ "$$", PWord1), vbInformation, HEADER 'leverage finding Pword by trying on other sheets ForEach w2 In Worksheets w2.Unprotect PWord1 Next w2 ExitDo'Bypass all for...nexts EndIf Next:Next: Next: Next: Next: Next Next:Next: Next: Next: Next: Next LoopUntilTrue OnErrorGoTo0 EndIf EndWith Next w1 EndIf MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER EndSub