To open a Windows application from Excel VBA, use the Shell function with the full path to its executable, enclosed in quotation marks; for example: Shell """C:\Program Files\Example\Example.exe""", vbNormalFocus. If the path contains spaces, those quotation marks are essential. The example below shows a safer macro that checks the path before launching the app.
Launch an executable with Shell
In Excel for Microsoft 365 on Windows, Shell starts a program and returns a task identifier. It does not wait for the application to finish, and that identifier is not a direct way to control the window afterward. Choose a window style such as vbNormalFocus to request a normal, focused window.
Here is a complete example. Replace the sample path with the actual location of the application’s executable file. Save a copy of the workbook before running a macro: VBA actions cannot be reversed with Ctrl+Z.
Sub OpenAppByPath()
Dim appPath As String
Dim taskId As Double
' Set this to the application's executable file.
appPath = "C:\Program Files\Example\Example.exe"
' Stop with a useful message if the file is missing.
If Len(Dir$(appPath)) = 0 Then
MsgBox "The application was not found:" & vbCrLf & appPath, vbExclamation
Exit Sub
End If
On Error GoTo LaunchError
' Quote the executable path so spaces are handled correctly.
taskId = Shell("""" & appPath & """", vbNormalFocus)
Exit Sub
LaunchError:
MsgBox "Excel could not start the application. " & Err.Description, vbExclamation
End Sub
In the VBA editor, insert the code in a standard module, then run OpenAppByPath. In Windows Excel, open the editor with Alt+F11; on a Mac, the editor shortcut is usually Option+F11, sometimes with Fn as well depending on the keyboard and system settings. You can also run a macro from the Developer tab or the Macros dialog. A workbook containing VBA must be saved in a macro-enabled format such as .xlsm if you want to keep its code.
What “open by file path” means
A file path is the location Windows uses to identify a file. An application path normally points to an executable, often ending in .exe, such as C:\Program Files\Vendor\Tool\Tool.exe. This is different from a path to a document, such as C:\Reports\summary.xlsx. To start a particular app directly, give Shell the executable path. Giving it a document path is not a reliable substitute for specifying an application.
Paths can be absolute or relative. An absolute path states the full location from a drive letter, while a relative path depends on a current folder that may differ between computers or between runs. For a workbook shared with coworkers, a hard-coded path under one person’s profile—such as a folder in C:\Users\Alex—is likely to fail for someone else. Install locations can also vary between PCs, software versions, and 32-bit or 64-bit installations.
Quotation marks protect a path containing spaces from being interpreted as multiple command-line pieces. In VBA, the expression """" & appPath & """" constructs a quotation mark, the path, and a closing quotation mark. The extra quote characters are VBA’s way of representing a literal quote inside a string.
Check and choose the application path
Before writing a fixed path into a macro, locate the actual executable on the computer where the macro will run. A shortcut’s Properties dialog can show its target, though the shortcut itself is not the executable. Use the target path, and verify that it points to the application file rather than a folder or an installer. If an app is installed through the Microsoft Store or another managed deployment system, its launch mechanism may not be a simple, stable executable path available to every user.
The Dir$ check in the example catches a common mistake: a misspelled or unavailable file path. It does not prove that the program is safe, compatible, or able to start successfully. Windows permissions, security software, missing components, or an application-specific startup error can still prevent launch. The error handler catches VBA errors raised while attempting to start the program, but it cannot diagnose every error inside the program after it has started.
For a macro used on multiple computers, consider how the path will be maintained. Practical approaches include:
- Keep the executable location in a clearly labeled worksheet cell or a named range, then validate that value before using it.
- Ask the user to choose the executable path, rather than assuming every installation uses the same folder.
- Use a documented, managed installation path if an administrator deploys the same application consistently.
- Show a clear message when the configured file is missing instead of attempting to launch an unrelated file or silently doing nothing.
Do not search the entire drive on every macro run unless there is a specific need. Broad searches can be slow, may find several versions, and make it unclear which one the code will launch.
Pass a file or other arguments to the app
Many programs accept a document path or options after the executable path. Put the executable and each argument in the command string, quoting any individual path that contains spaces. For instance, this pattern starts Notepad with a text file open. The file path is treated as an argument to Notepad, not as part of the executable name.
Sub OpenTextFileInNotepad()
Dim appPath As String
Dim documentPath As String
Dim taskId As Double
' Set both paths to files that exist on this computer.
appPath = "C:\Windows\System32\notepad.exe"
documentPath = "C:\Reports\April notes.txt"
If Len(Dir$(appPath)) = 0 Or Len(Dir$(documentPath)) = 0 Then
MsgBox "Check that the application and document paths exist.", vbExclamation
Exit Sub
End If
' Quote the executable and the document argument separately.
taskId = Shell("""" & appPath & """ """" & documentPath & """", vbNormalFocus)
End Sub
This example assumes the app accepts a document path in that position. Command-line options are defined by each application, so check that app’s documentation before adding switches. If an argument itself needs special handling, such as embedded quotation marks, follow the application’s command-line rules rather than assuming that adding quotes works for every program. When constructing a command from worksheet input, validate the input and quote each argument correctly; never treat untrusted cell contents as safe command text.
Open a document with its default application
Sometimes the goal is not to start a specific executable but simply to open a file using whichever program Windows associates with its file type. For example, a PDF might open in a PDF reader, while a spreadsheet might open in Excel. In that situation, a hyperlink-following approach can be more suitable than hard-coding one application’s installation path:
Sub OpenFileWithAssociatedApp()
Dim filePath As String
' Set this to the document to open.
filePath = "C:\Reports\summary.pdf"
If Len(Dir$(filePath)) = 0 Then
MsgBox "The document was not found: " & filePath, vbExclamation
Exit Sub
End If
' Ask Excel to follow the local file address.
ThisWorkbook.FollowHyperlink Address:=filePath
End Sub
This asks Windows and the available file association to handle the document; it does not guarantee which viewer will open it. Behavior can depend on Windows settings and organizational security policies. Use the executable-based Shell method when selecting a particular application matters. Use a document-opening method when using the user’s default app is the desired behavior.
Common errors and ways to fix them
If nothing opens, first check the exact executable path. A folder path is not an executable path, and an application shortcut’s location is not necessarily its target. Confirm the file exists on the computer that runs the macro, then try launching it from Windows independently. If it fails outside Excel, the issue is probably the installation, permissions, or application configuration rather than the VBA command.
If the path contains spaces and Windows reports that it cannot find the file, make sure the executable path is quoted as shown. If the app opens but does not load the requested document, check the app’s supported command-line format and whether the document argument is separately quoted. A program may ignore arguments it does not recognize.
Other common causes include:
- Macro blocking: Excel may block macros from an untrusted or downloaded workbook. Check the organization’s policy and use only trusted, approved files.
- Wrong machine or user folder: The macro may refer to a path that exists only on its author’s PC.
- Permissions: The user running Excel may not have permission to access the executable, its folder, or the requested document.
- Multiple app versions: A path may launch an older or different installation than intended.
- Misunderstood success: A positive task identifier from
Shellindicates a launch attempt; it does not confirm that the app finished loading the intended file.
For diagnosis, temporarily display the assembled command string in a message box before calling Shell. Check that the executable and arguments appear in the right order and that every path with spaces has its own pair of quotes. Avoid leaving sensitive paths or user data exposed in diagnostic messages when distributing the workbook.
Security, Excel versions, and platform limits
A macro that launches an application can have effects outside the workbook. Only run VBA from a source you trust, and do not enable all macros globally just to make one workbook work. In Excel for Windows, macro controls are under File > Options > Trust Center > Trust Center Settings > Macro Settings. Organizations may manage these settings centrally, so follow your administrator’s rules. A macro-enabled file should be reviewed before use, especially if it builds a command from cells, external data, or user input.
These examples are for desktop Excel on Windows. Excel for the web does not run VBA macros. Excel for Mac supports VBA in desktop Excel, but Windows executable paths such as C:\Program Files\... and Windows command-line behavior do not apply there. Mac application locations and launch mechanisms differ, so create and test a Mac-specific implementation rather than expecting the Windows code to work unchanged. If users on both platforms need the feature, identify their platform and provide separate, documented handling.
Finally, opening another app is not the same as automating it. Shell starts a process; it does not provide a general, cross-application way to click buttons, read the other app’s screen, or know when a task is complete. If the goal is to transfer data or automate a workflow, look first for a supported API, an Office integration, or an approved command-line interface. Those approaches are generally more predictable than relying on window timing.
Frequently Asked Questions
Can Excel VBA open an app using only its name?
Sometimes Windows can resolve a program name, but relying on that resolution can be ambiguous and dependent on the computer’s environment. Use the full executable path when you need to launch a particular app reliably.
How do I handle spaces in a file path?
Put quotation marks around the executable path and around each argument path that contains spaces. In VBA, double quotation marks inside a string are written as pairs, which is why the Shell examples contain several quote characters.
Can I open a file in its default app instead?
Yes. Excel’s ThisWorkbook.FollowHyperlink method can follow a local file address, allowing Windows’ file association to handle it. The app selected depends on the user’s system settings and policies.
Why does my macro work on one computer but not another?
The executable may be installed in a different folder, the user may lack access, or the macro may refer to a personal folder or app version. Validate paths on each target computer or make the path configurable.
Will this work in Excel for the web or on a Mac?
Excel for the web does not execute VBA. The Windows example is not portable to Mac because Mac app paths and launch behavior differ; a Mac implementation needs its own platform-appropriate code.
Related
- Microsoft Excel Format Cells: A Practical Guide for Data
- Microsoft Excel Employee Schedule Template: Setup Tips
- Microsoft Excel Debt Payoff Template: Build a Reliable Plan
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Erase Array: What It Does and When to Use ItIn Excel VBA, use Erase arrayName to reset an array: it releases the allocated storage of a dynamic…
- Creating Macros in Google Sheets: A Practical GuideTo create a macro in Google Sheets, open the spreadsheet in a web browser and choose Extensions >…
- VBA Range Sum: Methods, Examples, and Common ErrorsTo sum a range in Excel VBA, use Application.WorksheetFunction.Sum and assign its result to a variable or cell.…
- VBA MsgBox Context: What It Means and How to Use ItIn VBA, the context argument in MsgBox is a numeric help-topic identifier: it tells the associated help system…
- Excel VBA Lowercase: Use LCase in Macros and FunctionsIn Excel VBA, use the built-in LCase function to convert text to lowercase; its string-returning counterpart, LCase$, is…
- Excel VBA MsgBox Custom Buttons and ChoicesExcel VBA’s built-in MsgBox cannot create arbitrary button captions such as “Continue” or “Skip”; it offers fixed button…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.