Yes, you can open Notepad directly from Excel using VBA (Visual Basic for Applications) by calling the Windows Shell command. This is useful for logging, quick text notes, or automating workflows where you need to drop text into Notepad after processing data in Excel. No extra software is required—Excel and Windows are enough.
What You'll Need
- Microsoft Excel installed (Excel 2010 or later; works on Windows only)
- Basic familiarity with the VBA editor (Alt+F11 to open)
- Notepad available (standard on all current Windows versions)
Step-by-Step
- Open your Excel workbook and press Alt+F11 to launch the Visual Basic for Applications editor.
- In the VBA editor, go to Insert > Module. This adds a new blank code module to your project.
- Copy and paste the following VBA code into the module window:
Sub OpenNotepad() Shell "notepad.exe", vbNormalFocus End SubThis code uses the WindowsShellfunction to runnotepad.exewith normal window focus. - Save your workbook as a macro-enabled file (.xlsm) by going to File > Save As, then choose Excel Macro-Enabled Workbook (*.xlsm) from the 'Save as type' dropdown.
- Return to Excel and press Alt+F8 to open the Macro dialog box.
- Select OpenNotepad from the list and click Run. Notepad should open immediately.
Common Mistakes
- Macro security blocking execution: If Excel disables macros by default, the code won’t run. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and choose Enable all macros (only for trusted workbooks) or enable macros when prompted upon opening.
- Using wrong shell syntax: Typing
Shell "notepad", vbNormalFocus(missing.exe) may work on some systems but is unreliable. Always include.exefor consistency. - Running on macOS or Excel for web: This VBA method only works on Windows desktop Excel. Excel for Mac (pre-2021) and Excel Online do not support the
Shellfunction. - Not saving as .xlsm: If you save as .xlsx, macros are stripped and the code disappears. Always use .xlsm for macro-enabled files.
Tips
- To open Notepad with a specific file, modify the code:
Shell "notepad.exe C:\path\to\file.txt", vbNormalFocus. Replace the path with your actual file location and ensure the path uses double backslashes (\\) or forward slashes. - Use
vbMaximizedFocusorvbMinimizedFocusinstead ofvbNormalFocusto control window state (e.g.,Shell "notepad.exe", vbMaximizedFocus). - For automation, you can combine this with text-writing code using the
FileSystemObjectto create a temporary file, then open it in Notepad. - Test the code in a new workbook first—avoid running macros in sensitive production files until you’re confident.
Troubleshooting
If Notepad doesn’t open or you get an error, follow these checks in order:
- Restart Excel and re-run the macro. Sometimes the VBA environment locks up or macros are disabled silently.
- Verify macro security: Open Excel, go to Developer tab > Macro Security (or File > Options > Trust Center), and ensure macros aren’t disabled. If the Developer tab is missing, enable it via File > Options > Customize Ribbon and check Developer.
- Check for typos in the VBA code. Ensure
Shellis capitalized correctly (VBA is case-insensitive, but misspellingnotepad.exeorvbNormalFocuswill cause errors), and that the line is not split across lines incorrectly. - Confirm Windows path: Try running
notepad.exemanually from the Run dialog (Win+R, typenotepad.exe, press Enter). If this fails, your system’s Notepad path or registry entry may be corrupted—run sfc /scannow in Command Prompt (as admin) to repair system files. - Use full path explicitly: Replace
notepad.exewith the full path:Shell "C:\Windows\System32\notepad.exe", vbNormalFocus. This avoids issues ifnotepad.exeisn’t in the system PATH. - Check for antivirus interference: Some security software blocks shell execution from Office apps. Temporarily disable real-time protection (if safe to do so) and retry.
Frequently Asked Questions
Does this work on Excel for Mac?
No. Excel for Mac does not support theShell function. You’d need AppleScript or third-party tools to launch Notepad (or TextEdit) from Mac Excel—this is not natively supported.
Can I open Notepad with a specific file already loaded?
Yes. Change the code to include a file path:Shell "notepad.exe ""C:\Users\YourName\Documents\notes.txt""", vbNormalFocus. Note the double quotes around the path are required for paths with spaces; escape them in VBA by doubling the inner quotes.
How do I close Notepad after a delay?
You can add a timer and useSendKeys to close it, but this is risky and unreliable. A safer method is to open a temporary file, write to it, then close Notepad programmatically using Windows API calls—but that’s advanced. For most users, keep Notepad open and close it manually.
Why do I get a 'Compile error: Invalid outside procedure' message?
This happens if you placed the code directly in a worksheet or workbook event (likeWorksheet_Activate) without wrapping it in a Sub procedure. Ensure your code is inside a module under Sub OpenNotepad(), not in the code for a specific sheet.
Can I open Notepad as an administrator using VBA?
Not directly withShell alone. You’d need to use the ShellExecute Windows API with the runas verb, which requires more complex code and may trigger User Account Control (UAC) prompts. This is not recommended unless necessary, due to security risks.
What if Notepad opens but immediately closes?
This usually means the file path passed in the command is invalid or the file is locked. Remove any file path from the command and runShell "notepad.exe", vbNormalFocus alone. If Notepad opens normally, the issue is with the file path—not the VBA code itself.