Excel VBA Project Password Recovery
A VBA project password is not real encryption. Excel stores it as a weak flag inside xl/vbaProject.bin, and a ten-minute hex edit will clear it on any .xlsm, .xlsb, .xlam or .xla file from Excel 2007 through Excel 365. This guide walks through the exact byte sequences and explains why the trick works.
VBA Password vs Sheet Password vs Workbook Password
Excel has three password slots that users constantly confuse. They protect different things, use different storage, and recover with completely different techniques. Before opening a hex editor, be sure you are attacking the right one.
| Password type | Where it is set | What it protects | Storage | Recovery method |
|---|---|---|---|---|
| File (workbook) password | File → Info → Protect Workbook → Encrypt with Password | Whether Excel can open the file at all | AES-128 / SHA-512, 100,000 iterations (2010+) | GPU dictionary & mask attack |
| Sheet / workbook structure | Review → Protect Sheet / Protect Workbook | Editing cells or renaming tabs (advisory) | Plain XML sheetProtection tag, SHA-512 hash only | Delete the XML tag, 2-minute job |
| VBA project password | Alt+F11 → Tools → VBAProject Properties → Protection | Viewing / editing macro source code | DPB / GC / CMG keys in vbaProject.bin | Hex edit (this guide) |
If you cannot open the file at all, you have a workbook password — head over to Excel password recovery. If you can open it but cells are greyed out, see unprotect sheet without password. If the file opens, cells edit, but Alt+F11 prompts for a password, you are in the right place.
Why the VBA Password Is Weak
The VBA project password has never been real encryption. It was introduced in Office 97 as a courtesy lock so that colleagues would not accidentally browse your macro source. Microsoft documents it as obfuscation rather than encryption in the MS-OVBA specification. The macro code itself is stored in plaintext (as p-code and compressed source) inside vbaProject.bin. Only three metadata keys in the PROJECT stream tell Excel whether to prompt for a password:
- DPB — encrypted password hash, 32 bytes of hex text after the
DPB="marker. - GC — host-specific GUID blob (rare in modern files).
- CMG — command-bar signature used by older hosts.
If Excel cannot find DPB when it opens the file, it assumes there is no password. That is the entire basis of the hex-edit method: by renaming DPB= to anything else, you hide the key from Excel's parser. The file loads, you accept a warning, and you set a new password (or clear it) from the Visual Basic editor.
Exact Byte Sequences You Will Search For
Inside vbaProject.bin, the PROJECT stream is stored as a UTF-8 text blob. Open the file in HxD, 010 Editor or any hex editor and search by ASCII string:
| ASCII to find | Hex bytes | Replace with (ASCII) | Replace hex |
|---|---|---|---|
| DPB= | 44 50 42 3D | DPx= | 44 50 78 3D |
| CMG= | 43 4D 47 3D | CMx= | 43 4D 78 3D |
| GC= | 47 43 3D | Gx= | 47 78 3D |
| ID=" | 49 44 3D 22 | Leave unchanged | — |
Important: overwrite the single letter only, do not delete or insert bytes. File size and every offset must stay identical or the OLE2 directory inside vbaProject.bin will be corrupt. If your hex editor has an "insert" mode, switch it off.
Step-by-Step Procedure
- Make a copy. Duplicate
Book.xlsmand work on the copy. If you corrupt the PROJECT stream, Excel will refuse to open the file at all. - Open the .xlsm with 7-Zip. Right-click the file → 7-Zip → Open Archive. You will see
xl/,_rels/,docProps/, and[Content_Types].xml. - Drag out
xl/vbaProject.bin. Copy it to the desktop. Keep 7-Zip open — you will drag the edited file back in a moment. - Open vbaProject.bin in HxD. Press Ctrl+F, switch to Text-string mode, search for
DPB=. - Overwrite 'B' with 'x'. The third letter is at offset +2 from DPB. In HxD, click on the 'B' (hex 42) and type
78in overwrite mode. - Repeat for CMG. Search
CMG=, change 'G' (hex 47) to 'x' (hex 78). - Save the file. Ctrl+S. Size must be identical — HxD shows it in the status bar.
- Drag the edited vbaProject.bin back into 7-Zip. Replace the file inside the
xl/folder. 7-Zip will update the archive in place. - Open Book.xlsm in Excel. You will see: "Unexpected error. Continue loading project?" — click Yes. Then: "The VBA project cannot be read." — click OK. Both are normal.
- Press Alt+F11 to open the Visual Basic editor. The project now loads without a password prompt.
- Right-click VBAProject → VBAProject Properties → Protection tab. Uncheck "Lock project for viewing" or set a new password of your choice.
- Save, close, reopen. The next time you open Alt+F11, there is no password prompt. The two warnings also disappear after the save.
.xla / .xlam / Old .xls Files — A Note on Binary OLE
Excel add-ins saved as .xla and binary workbooks saved as .xls are pure OLE2 compound files, not ZIP. There is no outer archive to open, but the PROJECT stream is still there — you can search the raw file directly. The DPB / CMG / GC byte sequences and the rename technique are identical.
For OLE2 files, make sure your hex editor does not re-calculate the internal FAT or directory after saving. HxD, 010 Editor and WinHex all write back faithfully. Built-in Windows Notepad and any editor that normalizes line endings will destroy the file.
Things that will ruin the file
- Editing vbaProject.bin in a text editor — it silently rewrites encoding.
- Letting your hex editor run in "insert" mode — shifts every byte after.
- Repacking the .xlsm with WinRAR "Best" compression — Excel reads Deflate only. 7-Zip defaults are fine.
- Saving the file before you finish adjusting the VBA password in Alt+F11 — warnings persist on every open.
When the Hex Edit Does Not Work
A small number of corporate templates use a non-standard VBA project signature written by third-party tools (e.g. some document-management plugins). In those files, the DPB / CMG rename will make Excel reject the project entirely rather than warn-and-continue. Symptom: you open Alt+F11 and the VBAProject tree is empty.
Fix: revert to your backup and try an alternative route — copy all modules into a fresh, unprotected workbook. In Alt+F11 right-click each module → Export File, then import into the new workbook. Forms (UserForms) carry across the same way. It is tedious but never fails, because you are copying the plaintext code out of a file you can already read.
Need the workbook password, not the VBA one?
If the file itself will not open, the VBA trick will not help you — the archive never reaches the VBA parser. Upload your file to our main recovery service instead. For files saved as Excel 97-2003 .xls, recovery is guaranteed.
Frequently Asked Questions
Is the VBA project password the same as the workbook password?
No. The workbook password protects the whole file with AES. The VBA password is a soft lock on viewing macros — a file with a VBA password still opens normally in Excel.
Does this work on .xlsb and .xlam?
Yes. All Open XML formats since Excel 2007 share the same vbaProject.bin layout: .xlsm, .xlsb, .xlam, plus the legacy binary .xls and .xla.
Will Microsoft patch this?
Very unlikely. Microsoft has documented the VBA password as obfuscation for 25 years. Changing it would break every third-party tool that signs, audits or repackages VBA projects.
Are my macros destroyed after the edit?
No. The macro source and compiled p-code are in separate streams. Only the password metadata changes. After a resave the compiled cache refreshes — worst case is a single re-compile pause on first run.
Is there a tool that does all this automatically?
Several free utilities exist, but they are typically flagged by corporate antivirus because the same technique is used in macro-based malware. The manual hex-edit method is safer because it uses only a standard hex editor and 7-Zip.