Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 電腦軟體介紹

破解 Excel 工作表保護密碼:VBA 巨集移除法

編輯:電腦軟體介紹

忘記 Excel 工作表保護密碼時,可透過錄製巨集並注入 VBA 程式碼來移除保護。此方法適用於 Excel 2003 及以上版本,操作前請務必備份原檔案。

操作步驟

  1. 開啟受保護的 Excel 檔案。
  2. 依序點選「工具」→「巨集」→「錄製新巨集」,巨集名稱自訂(如 PeJie)。
  3. 點選「停止錄製」,得到一個空巨集。
  4. 再次進入「工具」→「巨集」→「巨集」,選取 PeJie → 點擊「編輯」進入 VBE 編輯器。
  5. 刪除視窗中所有程式碼,貼上以下 VBA 代碼:
Option Explicit

Public Sub 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 As String = vbNewLine & vbNewLine
Const AUTHORS As String = DBLSPACE & vbNewLine & _
"Adapted from Bob McCormick base code by" & _
"Norman Harker and JE McGimpsey"
Const HEADER As String = "AllInternalPasswords User Message"
Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04"
Const REPBACK As String = DBLSPACE & "Please report failure " & _
"to the microsoft.public.excel.programming newsgroup."
Const ALLCLEAR As String = 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 As String = "No passwords found."
' ...(後續代碼省略,請參考完整原始碼)
End Sub
  1. 按 F5 執行巨集,執行完成後工作表保護即被移除。
  2. 立即另存新檔,並妥善備份。

⚠ 注意事項:

  • 此程式碼僅移除保護,不會破解原始密碼。
  • 操作前請務必備份原始檔案,以免資料遺失。
  • 請勿用於非法用途,僅供個人合法文件恢復使用。

Office 2003 精簡版下載:連結

Copyright © Windows教程網 All Rights Reserved