Excel can't password-protect an XML file directly, and it can't lock a .xml document behind a password the way it can a workbook. What it can do is open the XML, resave it as an .xlsx or .xlsm workbook, and protect that workbook with a password. This protects the data only after conversion, and it changes the file format. If you need the file to stay XML, you'll need file-level encryption from another tool, such as BitLocker, 7-Zip, or a password manager vault, since Excel has nothing to offer on that front.

What You'll Need

  • A desktop version of Excel (Windows or Mac). Excel for the web can't set workbook passwords, so these steps need the desktop app.
  • The XML file on your own computer, not in a synced folder that auto-uploads if you'd rather not risk unencrypted copies floating around.
  • A firm password you won't lose. Excel passwords cannot be recovered by normal means, and password cracking tools exist that some people rely on.
  • Optional: a compression tool such as 7-Zip if you want to encrypt the file while keeping the .xml extension.

Step-by-Step

  1. Back up the XML file first. Copy it to another folder or drive. Once Excel resaves the file as a workbook, the original XML formatting, schema structure, and any custom tags can behave differently. A simple copy protects you.
  2. Open the XML in Excel. Launch Excel, go to File > Open > Browse, select the .xml file, and click Open. Excel will usually show the Open XML dialog offering As an XML table, As a read-only workbook, or Use the XML Source task pane. Pick As an XML table if the file has a simple, flat structure; Excel may warn that it will create a schema based on the data, which is expected.
  3. Confirm or dismiss the schema warning. Click OK to let Excel build the table. If Excel says the file cannot be opened because of schema issues, skip ahead to the Troubleshooting section, because forcing it through will lose data.
  4. Check the data landed correctly. Scan the columns for missing values, shifted rows, or numbers stored as text. Fix anything obviously broken before you lock it, since a locked workbook makes editing harder.
  5. Save as a workbook, not XML. Go to File > Save As. Set Save as type to Excel Workbook (*.xlsx) or Excel Macro-Enabled Workbook (*.xlsm). Give it a name and save it somewhere sensible. This conversion is the core of the process: the password applies to the workbook, not the original .xml file.
  6. Open the password options. With the new workbook open, go to File > Info, click Protect Workbook, and choose Encrypt with Password. In older builds you'll find the same option under File > Save As > Tools > General Options. Labels shift slightly between versions, so if you don't see it, look for anything saying "password" or "encrypt".
  7. Enter the password twice. Type it into the Password box, click OK, then retype it. Excel will offer to save, and you should save immediately, because the password isn't applied until the file is written.
  8. Test it properly. Close the workbook completely, open it again, and confirm Excel asks for the password before showing any data. If it opens without a prompt, the password didn't stick, so repeat step 6.
  9. Decide what to do with the original XML. If the data is sensitive, delete or move the unprotected original to a safe location. Leaving it sitting there defeats the purpose, because anyone with access can open it.

Common Mistakes

  • Assuming the .xml file itself is now protected. It isn't. The password lives on the .xlsx copy. If you still have the original XML, anyone can read it.
  • Using the wrong "Protect" option. Protect Sheet and Protect Workbook prevent edits but don't stop someone from opening and reading the file. Only Encrypt with Password does that.
  • Forgetting that protection is weaker than it looks. Old Excel formats (.xls) used weak encryption. Modern .xlsx uses stronger encryption, but it still depends on password strength, so a short password is the weak link.
  • Losing the password. There's no official recovery. Excel warns you at the point you set it, and that warning is real.
  • Saving over the XML. If you choose XML file types by habit, you'll defeat the whole exercise. Double-check the Save as type dropdown.
  • Storing the password in the same folder as the workbook. A text file called "password.txt" next to the file is a common and easily avoided mistake.

Tips

  • If your XML is large, use Data > Get Data > From File > From XML instead of opening it directly. This loads it as a query and gives cleaner, more reliable results with complex files.
  • Keep the password long and random. Length matters more than symbol tricks. A passphrase of four or five unrelated words is easy to type and hard to crack.
  • If you need to share the data but not let the recipient edit it, use File > Info > Protect Workbook > Always Open Read-Only alongside a password to discourage changes. That's a suggestion, not a security control, so don't rely on it alone for sensitive files.
  • For a truly protected .xml file, zip the XML into an archive with AES encryption using 7-Zip or Windows' built-in compressed-folder encryption. That keeps the .xml extension intact and enforces a password at the file level.
  • Email providers and cloud services often scan and index unencrypted files. Encrypt before uploading rather than after.

Troubleshooting

If the workbook opens without asking for a password: the save didn't complete after you set it. Reopen, set the password again, and make sure you click Save when Excel prompts. Then close and reopen to verify.

If you've forgotten the password: there is no built-in recovery. The official path is to restore an earlier unprotected copy from a backup or from your cloud service's version history, if one exists. Third-party password removal tools exist but are unreliable and can expose your file to risk, so treat them cautiously.

If Excel refuses to open the XML at all: the file may contain a namespace or structure Excel can't map. Try the As a read-only workbook option, or use Get Data > From XML in the Power Query editor, which handles awkward files better. If it still fails, the XML is likely malformed, and you should check it in a plain text editor or XML validator.

If the data arrives garbled or with odd characters: the XML encoding doesn't match what Excel expects. Saving the file as UTF-8 in a text editor usually fixes it.

If the workbook feels sluggish after conversion: large XML tables with thousands of rows slow Excel down. Password encryption adds a little overhead but not much. Consider importing as a query and keeping only the columns you need.

Frequently Asked Questions

Can I password protect an XML file directly in Excel?

No. Excel's password feature applies to workbooks (.xlsx, .xlsm, .xls), not to .xml files. You must convert the file to a workbook first, or encrypt the XML outside Excel with a compression or drive-encryption tool.

Does the password stop someone from opening the file at all?

Yes, if you used Encrypt with Password. Excel requires the password before showing anything. Protect Sheet and Protect Workbook do not behave this way; they let anyone open the file and only restrict editing.

Will the password survive if I convert the workbook back to XML?

No. Saving to XML strips the encryption, because XML is a plain-text format. You'd need to encrypt the resulting XML with another method.

Can I use this on Excel for the web?

Excel for the web can open and edit files but can't set workbook encryption passwords. Use the desktop app to apply the password, then the encrypted file will still prompt for it when opened online.

What happens if the password is lost?

The file can't be opened through normal means. There is no official unlock. Restore an earlier copy from backup or version history if you have one, and keep a record of the password in a secure password manager.

Is it safe to email the protected workbook?

Encrypted .xlsx files are reasonably safe to send, provided the password meets modern strength. Send the password through a separate channel, such as a phone call or a different messaging app, rather than in the same email.