XLS Macro Security: How to Inspect Legacy Workbooks Safely
Cover VBA, XLM macros, protected view, signatures, scanning and safe content extraction.
Macro Types in Legacy XLS Files
An XLS file can carry executable code in two distinct forms, defined in the binary file format specification [MS-XLS]. VBA macros reside in dedicated storage streams (_VBA_PROJECT_CUR), while Excel 4.0 (XLM) macros live on macro sheet records embedded in the workbook stream. A third concern is external references—formulas or defined names that trigger network requests when evaluated. Understanding these storage mechanisms determines which inspection method applies.
Verify Protected View Before Opening
Protected View is a sandbox that blocks macro execution, external data connections, and most active content. Confirm it is enabled before any manual inspection of an untrusted XLS.
- Open Excel. Go to File → Options → Trust Center → Trust Center Settings → Protected View.
- Verify all three options are checked:
- Enable Protected View for files originating from the internet
- Enable Protected View for files located in potentially unsafe locations
- Enable Protected View for Outlook attachments
- Click OK, then open the target XLS.
Observable check: The yellow message bar reads "Protected View—Be careful—files from the Internet can contain viruses." The Macros button on the View tab is grayed out. If the bar is absent and macros are available, the file opened outside Protected View—close it immediately and recheck your Trust Center settings.
Limitation: Protected View does not inspect the file; it only prevents execution. A file can still carry malicious code that would activate if the file were later moved to a trusted location or if a user clicks "Enable Editing" without inspection.
Detect VBA Macros Without Execution
Hex-Level Inspection
VBA project storage is signaled by the presence of the _VBA_PROJECT_CUR stream name inside the OLE2 compound document. Search the raw bytes:
# macOS / Linux
xxd yourfile.xls | grep -i "VBA_PROJECT"
# Windows PowerShell
Select-String -Path "yourfile.xls" -Pattern "VBA_PROJECT" -Encoding Byte
Observable check: If the string _VBA_PROJECT_CUR or VBA_PROJECT appears, the file contains a VBA project. Absence of this string means no VBA macros are embedded.
Limitation: This method confirms presence but does not reveal what the macros do. It also cannot detect VBA code stored in add-in (.xla) files referenced by the workbook.
VBA Editor in Protected View
Press Alt+F11. In Protected View, the VBA IDE opens but displays "Project is unviewable" or an empty project pane. This confirms Protected View is blocking code access. Do not exit Protected View to "take a quick look" at the code—once macros are enabled, auto-executing procedures (e.g., Workbook_Open) can run before the editor appears.
Locate Excel 4.0 (XLM) Macros
XLM macros are stored on macro sheets, which are worksheet substreams with a BOF record type of 0x0040 (macro sheet) rather than 0x0010 (worksheet). They do not appear in the VBA editor.
Sheet Tab Inspection
In Protected View, examine the sheet tabs at the bottom of the Excel window. Look for: - Tabs named "Macro1," "Macro2," or any name ending in a number that suggests a generated macro sheet. - Tabs with no visible cell data but a non-trivial file size.
Observable check: Right-click any suspicious tab and select View Code. In Protected View, this action is blocked. If you see a sheet with a single button or an empty grid, treat it as a potential macro sheet.
Binary Search for XLM Opcodes
XLM macros use human-readable function names. Search the file bytes for known XLM command strings:
grep -oba "EXEC\b\|HALT\|ECHO\|ALERT\|REGISTER" yourfile.xls
Observable check: Matches indicate XLM function calls exist in the binary. The -b flag gives byte offsets, which you can cross-reference with a hex editor to locate the surrounding macro sheet structure.
Limitation: This string search catches common opcodes but can miss obfuscated XLM where function names are constructed at runtime via CONCATENATE or stored in hidden names. A clean grep result reduces risk but does not eliminate it.
Inspect Digital Signatures
A digital signature on a macro-enabled workbook confirms integrity since signing. It does not validate the macro's safety.
- In Protected View, go to File → Info.
- Click View Signatures (if present).
- In the Digital Signatures dialog, select the signature and click Details.
Observable check: Examine the Signing time, the Issued by field, and whether the certificate chains to a trusted root. A self-signed certificate or one issued by an unknown CA provides no identity assurance. Click View Certificate → Certification Path to see the full chain.
Limitation: A valid signature from a known publisher only means the file hasn't changed since that publisher signed it. The publisher could have signed malicious code, or their certificate could be compromised. Treat signature validity as one signal among several.
Extract Data Without Executing Code
Non-Executing Viewers
These tools parse the XLS binary format and extract cell values without invoking the macro runtime:
- LibreOffice Calc: Open the file with macro security set to Very High or High (Tools → Options → LibreOffice → Security → Macro Security). Macros are disabled by default; verify the setting before opening.
- Google Sheets: File → Import → Upload. Google Sheets strips all VBA and XLM macros during import.
- Python
xlrd(≥2.0.0): This library reads cell data, formulas, and formatting from XLS files but explicitly removed support for.xlsmand macro execution paths. Install withpip install xlrd.
Command-Line Extraction to CSV
python -c "
import xlrd
wb = xlrd.open_workbook('yourfile.xls')
for sheet in wb.sheets():
for row in range(sheet.nrows):
print(','.join([str(sheet.cell_value(row, col)) for col in range(sheet.ncols)]))
" > output.csv
Observable check: The resulting CSV contains static cell values. Formulas appear as their last cached result (or 0 if never calculated). No macros, defined names, or VBA project streams survive the conversion.
Limitation: xlrd reads only the last cached value of formula cells. If the workbook was saved without a prior calculation, formula cells may be empty. XLM functions that dynamically populate ranges leave no trace in the extracted data.
What Safe Extraction Loses
Stripping macros and external references removes executable risk but also discards:
- Cached external data: Values pulled via
WEBSERVICE, VBAHTTPRequest, or DDE links are not refreshed. The extracted cells show the last saved values, which may be stale or blank. - VBA user-defined functions: Any cell containing
=MyCustomFunction(...)becomes#NAME?in the converted output. - XLM-driven formatting: Conditional formatting, row insertion, or cell protection applied by XLM commands during runtime is absent.
- Hidden names and very hidden sheets:
xlrdexposes hidden sheets but not those markedxlSheetVeryHiddenvia VBA. Checkwb.sheet_visiblefor each sheet index to identify sheets thatxlrdcannot read.
If the extracted dataset contains #NAME? errors, blank columns where data is expected, or references to external sources in leftover formula text, the original workbook likely depended on macro execution. The missing data is unrecoverable without running the code in a controlled, isolated environment.
Technical basis for XLS Macro Security
Structural claims in this guide are grounded in the primary XLS technical reference.