Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Note: The function, method, object, or property described in this topic is disabled if the Microsoft Jet Expression Service is running in sandbox mode, which prevents the evaluation of potentially unsafe expressions. For more information on sandbox mode, search for "sandbox mode" in Help.

Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.

Syntax

Shell( pathname [, windowstyle ] )

The Shell function syntax has these arguments:

Argument

Description

pathname

Required. Variant (String). Name of the program to execute and any required arguments or command line switches; may include directory or folder and drive. On the Macintosh, you can use the MacID function to specify an application's signature instead of its name. The following example uses the signature for Microsoft Word: Shell MacID("MSWD")

windowstyle

Optional. Variant (Integer) corresponding to the style of the window in which the program is to be run. If windowstyle is omitted, the program is started minimized with focus. On the Macintosh (System 7.0 or later), windowstyle only determines whether or not the application gets the focus when it is run.


The windowstyle named argument has these values:

Constant

Value

Description

vbHide

0

Window is hidden and focus is passed to the hidden window. The vbHide constant is not applicable on Macintosh platforms.

vbNormalFocus

1

Window has focus and is restored to its original size and position.

vbMinimizedFocus

2

Window is displayed as an icon with focus.

vbMaximizedFocus

3

Window is maximized with focus.

vbNormalNoFocus

4

Window is restored to its most recent size and position. The currently active window remains active.

vbMinimizedNoFocus

6

Window is displayed as an icon. The currently active window remains active.


Remarks

If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.

On the Macintosh, vbNormalFocus, vbMinimizedFocus, and vbMaximizedFocus all place the application in the foreground; vbHide, vbNoFocus, vbMinimizeFocus all place the application in the background.

Note:  By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.

Example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

This example uses the Shell function to run an application specified by the user. On the MacIntosh, the default drive name is “HD” and portions of the pathname are separated by colons instead of backslashes. Similarly, you would specify Macintosh folders instead of \Windows.

' Specifying 1 as the second argument 
' opens the application in normal size and
' gives it the focus.
Dim RetVal
' Run Calculator.
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×