Yes, you can start Notepad directly from Excel VBA using the Shell function. This automates opening a blank Notepad window—ideal for logging output, writing quick notes, or integrating text editing into a larger VBA workflow. No extra tools are required beyond Excel itself (with VBA enabled) and Windows, as Notepad is a built-in Windows application.

What You'll Need

  • Microsoft Excel installed (Excel 2010 or later recommended, but works in most versions)
  • VBA enabled in Excel (macro security set to allow macros)
  • Windows operating system (Notepad is Windows-native; this does not work on macOS)

Step-by-Step

  1. Open Excel and create a new blank workbook (or use an existing one where you want to add the feature).
  2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  3. In the VBA editor, go to Insert > Module to add a new code module to your workbook.
  4. Copy and paste the following VBA code into the module window:
    Sub StartNotepad()
        Dim notepadPath As String
        notepadPath = "notepad.exe"
        Shell notepadPath, vbNormalFocus
    End Sub
    This code defines a subroutine named StartNotepad, sets the target executable to notepad.exe, and uses the Shell function to launch it with normal window focus.
  5. Close the VBA editor and return to Excel.
  6. Press Alt + F8 to open the Macro dialog box.
  7. Select StartNotepad from the list and click Run.
  8. Notepad should open immediately. If it does not, check the troubleshooting section below.

Common Mistakes

  • Typing notepad without the .exe extension: While Windows often resolves this automatically, VBA's Shell function is strict about full paths or executable names. Always include .exe to ensure reliability.
  • Running on macOS: Notepad is exclusive to Windows. This method will fail silently or return an error on non-Windows systems.
  • Macro security blocking execution: If macros are disabled, the code will not run. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable all macros (temporarily, for testing only), then re-enable notifications for production use.
  • Not declaring the variable: Omitting Dim notepadPath As String can cause runtime errors if Option Explicit is used at the top of the module. Always declare variables or remove Option Explicit if you prefer implicit declaration (not recommended for production).
  • Using incorrect capitalization: VBA is case-insensitive, but mixing case in paths (e.g., Notepad.exe vs. notepad.exe) can cause confusion when debugging. Stick to lowercase for Windows executables.

Tips

  • Open Notepad with a file: Modify the Shell line to open a specific file, like Shell "notepad.exe C:\temp\log.txt", vbNormalFocus. Ensure the file path uses double backslashes (\\) or forward slashes (/) to avoid escape-character issues.
  • Wait for Notepad to close: The Shell function starts Notepad asynchronously. To wait until the user closes Notepad, use Windows API calls (e.g., CreateProcess and WaitForSingleObject), but this adds complexity and is rarely needed for simple text editing.
  • Use the full path for reliability: If Notepad is missing from the system PATH (rare), use the full path: Shell "C:\Windows\System32\notepad.exe", vbNormalFocus.
  • Test in a new workbook first: Avoid corrupting a live project by testing new macros in a blank workbook before adding them to critical files.
  • Save as .xlsm: Always save your Excel file as Excel Macro-Enabled Workbook (*.xlsm) to preserve VBA code. Saving as .xlsx strips macros.

Troubleshooting

If Notepad does not open when you run the macro, follow these steps in order:

  1. Verify macro execution: After pressing Alt + F8, ensure StartNotepad appears in the macro list. If not, re-paste the code and confirm it is inside a Sub ... End Sub block in a standard module (not in ThisWorkbook or a worksheet module).
  2. Check for runtime errors: Press F5 while in the VBA editor to run the macro directly. If an error appears (e.g., "File not found"), double-check the notepadPath string and ensure it exactly matches "notepad.exe".
  3. Confirm Windows Notepad exists: Press Win + R, type notepad, and press Enter. If Notepad does not open, your system may be corrupted. Reinstall Notepad via Settings > Apps > Optional Features, or run sfc /scannow in Command Prompt as Administrator.
  4. Check macro security: In Excel, go to Developer > Macro Security (if the Developer tab is hidden, enable it via File > Options > Customize Ribbon). Set it to Enable all macros temporarily. If it works after this change, adjust security to Disable all macros with notification and digitally sign your macro later.
  5. Run Excel as Administrator: Some corporate or locked-down systems block shell commands. Right-click Excel, select Run as administrator, and try again. If it works, your user account lacks permissions to launch external processes.
  6. Antivirus interference: Security software may block Shell calls. Temporarily disable real-time protection (if safe to do so) and test. If successful, add an exclusion for Excel in your antivirus settings.

Frequently Asked Questions

Does this work on Excel for Mac?

No. Notepad is a Windows-only application. On macOS, you can use the equivalent TextEdit app by changing the path to "/Applications/TextEdit.app", but this requires AppleScript and is not compatible with Windows Excel. Cross-platform automation is not supported natively.

Can I pass text to Notepad when it opens?

Not directly via Shell. You can write text to a temporary file first, then open that file in Notepad: Shell "notepad.exe C:\temp\temp.txt", vbNormalFocus, where temp.txt contains your desired content. Use VBA's Open statement to create and write to the file before launching Notepad.

Why does Notepad open minimized or hidden?

The Shell function uses the second argument to control window state. vbNormalFocus restores and focuses the window. Use vbMinimizedFocus for minimized, vbMaximizedFocus for maximized, or vbHide to hide it. If you see no window, check your antivirus or task manager—the process may be running but not visible.

How do I close Notepad automatically after a delay?

VBA cannot directly close external apps like Notepad after a delay without Windows API calls. A workaround is to open Notepad with a temporary file, write your content, then use Application.OnTime to schedule a macro that sends Alt + F4 via SendKeys. However, SendKeys is unreliable and can send keystrokes to the wrong window. Use only in controlled environments.

Can I launch Notepad with a specific font or size?

No. Notepad does not support command-line arguments for font or window size. You must open Notepad and adjust settings manually, or use a different text editor (like VS Code or Notepad++) that supports CLI arguments.

Is there a security risk in using Shell to launch Notepad?

Minimal risk if you hardcode "notepad.exe". The danger arises if you pass user input directly into the Shell command (e.g., Shell InputBox("Enter path")), which could execute malicious commands. Always validate and sanitize inputs, or avoid dynamic paths entirely for simple tasks like this.