How to Use an Excel VBA Macro to Start an EXE Application
Question details
The user wants to run a VBA macro in Excel to launch an external executable application, such as Notepad.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating workflows by opening an external program directly from an Excel workbook without leaving the spreadsheet environment.
- Observed behavior
- The goal is to successfully execute an external application via a VBA script using the built-in Shell function.
Ensure that you have enabled the Developer tab in your spreadsheet software and that your macro security settings are configured to allow VBA scripts to run.
Use the VBA Shell Function to Launch an Application
The most straightforward way to run an executable file from a macro is by utilizing the built-in VBA Shell function.
The Shell function initiates an executable program and returns a double-precision integer representing the program's task ID if successful. It also allows you to specify the window style, such as launching the application maximized, minimized, or hidden in the background.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
Click on 'Insert' in the top menu, then select 'Module' to create a blank script window.
Type the following code into the module window: Sub StartApp() Shell "notepad.exe", vbMaximizedFocus End Sub
If the application is not in the system path, replace 'notepad.exe' with the full file path of the specific application you want to open (for example, "C:\\Program Files\\App\\app.exe").
Press F5 or click the Run button on the top toolbar to execute the macro and launch the specified application.

Run VBA Macros Seamlessly in WPS Spreadsheet
WPS Office Spreadsheet fully supports VBA macros, allowing you to automate tasks and execute Shell functions just like you would in Microsoft Excel. It offers a highly compatible and familiar environment for all your data processing needs.
- 1. Download WPS Office: Install WPS Office and open your .xlsm or .xlsb macro-enabled workbook in WPS Spreadsheet.
- 2. Enable Developer Tools: Navigate to the Developer tab to access the VBA Editor and adjust your macro security settings.
- 3. Run Your Shell Macro: Execute your macro code to flawlessly launch external applications directly from your WPS spreadsheet.

Frequently Asked Questions
Can I use a VBA macro to open a specific file in the launched application?
Yes. Within the Shell function, you can append the file path after the application executable name, for example: Shell "notepad.exe C:\\path\\to\\your\\file.txt", vbNormalFocus.
Why do I get a 'File not found' error when running the macro?
This usually happens when the application's executable is not included in your system's PATH. To fix this, provide the full file path to the executable, such as Shell "C:\\Windows\\System32\\notepad.exe".
How do I make the application open in the background without taking screen focus?
You can change the window style argument in the Shell function from vbMaximizedFocus to vbHide, vbMinimizedNoFocus, or vbNormalNoFocus to run the application invisibly or minimized without interrupting your current workflow.




