Fix Excel VBA Macro Notepad Cannot Be Found Error When Saving XML
Question details
The user needs an Excel XLSB VBA macro to generate and save XML without failing when it tries to open Notepad.

- Product
- Microsoft Excel for Microsoft 365 VBA macro
- Device & OS
- Windows 11
- Scenario
- The macro generates XML text, opens Notepad, pastes the XML content, and saves the resulting file.
- Observed behavior
- Some users receive a “Notepad cannot be found” error, while the same macro works for other Windows users.
Run the macro while signed in to an affected Windows account so you can test its actual executable and folder access. Identify the VBA line that calls Notepad, such as a Shell command, and confirm the intended XML output folder exists.
Replace the Notepad step with direct VBA XML file output
Use this solution for the most reliable result. VBA can save the generated XML directly, removing the dependency on Notepad, desktop locations, and application-control policies.
Opening Notepad only to paste and save generated XML adds unnecessary points of failure. Save the XML string directly to the target file after the macro finishes building it.
The example below uses a late-bound ADODB stream to create a UTF-8 XML file without requiring a VBA reference to be enabled.
In Excel, press Alt+F11 to open the Visual Basic Editor. Select the macro module and find the line that uses Shell, SendKeys, AppActivate, or a hard-coded Notepad or Desktop path.
In the VBA procedure, set a file path that the current user can access, for example: outputFile = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\Export.xml". Use ThisWorkbook.Path & "\Export.xml" instead if the workbook is saved in a writable folder.
After building xmlText, replace the Notepad and paste commands with: Set stm = CreateObject("ADODB.Stream"): stm.Type = 2: stm.Charset = "utf-8": stm.Open: stm.WriteText xmlText: stm.Position = 0: stm.SaveToFile outputFile, 2: stm.Close. The value 2 overwrites an existing Export.xml file.
Run the macro under the affected account, then open the saved Export.xml from File Explorer or import it into the receiving system. Confirm the XML declaration and file encoding match the requirements of the destination system.

Correct the VBA Shell command that launches Notepad
Use this option only when the workflow must still open the generated XML in Notepad for review or manual editing.
Use WPS Office for Lightweight Spreadsheet and VBA-Compatible Workflows
If Microsoft Excel or Windows policies continue to interfere with the macro workflow, WPS Office provides a free, lightweight office alternative with a familiar spreadsheet interface and strong compatibility with common Microsoft Office files. You can move existing workbook-based workflows to WPS Spreadsheets and reduce dependence on a specific Microsoft 365 installation.
- 1. Install WPS Office: Download and install WPS Office on the Windows computer that needs an alternative spreadsheet application.
- 2. Open the workbook in WPS Spreadsheets: Select Open in WPS Office and choose the existing Excel workbook to review its worksheets, formulas, and workflow requirements.
- 3. Validate the workbook workflow: Run non-destructive tests with a copy of the workbook and verify that the required spreadsheet functions and output files work as expected.

Frequently Asked Questions
Why does an Excel VBA macro find Notepad on one computer but not another?
The macro may use a hard-coded executable or user-folder path that does not exist for every account. Notepad may also be restricted by Windows policy, antivirus, AppLocker, or another application-control setting on the affected computer.
What is the safest VBA method for saving generated XML?
Write the XML string directly to a file rather than automating Notepad. In the Visual Basic Editor, use an ADODB.Stream with Charset set to "utf-8" and SaveToFile, or use VBA Open and Print for simple text output when the required encoding permits it.
How do I open Notepad from VBA when the XML file path has spaces?
Quote both the executable and the file path. For example, use Shell """" & Environ$("WINDIR") & "\System32\notepad.exe"" """" & outputFile & """", vbNormalFocus, where outputFile is the complete XML file path.
Should I save XML to a hard-coded Desktop path in an Excel macro?
No. A path such as C:\Users\Name\Desktop is account-specific and may be redirected by OneDrive or organization policy. Use WScript.Shell.SpecialFolders("Desktop") for the current user's Desktop, or save beside the workbook with ThisWorkbook.Path when that folder is writable.
Can Windows security settings block an Excel macro from opening Notepad?
Yes. Controlled Folder Access, endpoint security software, AppLocker, and organization device policies can block Notepad, macro-created processes, or writing to protected folders. Test Notepad manually under the affected account and ask the administrator to review the relevant event logs and policy rules.




