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

  1. Open your Excel workbook and press Alt+F11 to launch the Visual Basic for Applications editor.
  2. In the VBA editor, go to Insert > Module. This adds a new blank code module to your project.
  3. Copy and paste the following VBA code into the module window:
    Sub OpenNotepad()
        Shell "notepad.exe", vbNormalFocus
    End Sub
    This code uses the Windows Shell function to run notepad.exe with normal window focus.
  4. 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.
  5. Return to Excel and press Alt+F8 to open the Macro dialog box.
  6. 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 .exe for 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 Shell function.
  • 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 vbMaximizedFocus or vbMinimizedFocus instead of vbNormalFocus to control window state (e.g., Shell "notepad.exe", vbMaximizedFocus).
  • For automation, you can combine this with text-writing code using the FileSystemObject to 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:

  1. Restart Excel and re-run the macro. Sometimes the VBA environment locks up or macros are disabled silently.
  2. 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.
  3. Check for typos in the VBA code. Ensure Shell is capitalized correctly (VBA is case-insensitive, but misspelling notepad.exe or vbNormalFocus will cause errors), and that the line is not split across lines incorrectly.
  4. Confirm Windows path: Try running notepad.exe manually from the Run dialog (Win+R, type notepad.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.
  5. Use full path explicitly: Replace notepad.exe with the full path: Shell "C:\Windows\System32\notepad.exe", vbNormalFocus. This avoids issues if notepad.exe isn’t in the system PATH.
  6. 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 the Shell 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 use SendKeys 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 (like Worksheet_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 with Shell 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 run Shell "notepad.exe", vbNormalFocus alone. If Notepad opens normally, the issue is with the file path—not the VBA code itself.