Shell Function

Description

Runs an executable program.

Syntax

Shell(pathname[, windowstyle])

The Shell function syntax has these named arguments:

Part

Description

pathname

Name of the program to execute and any required arguments or command line switches; may include directory or folder and drive. May also be the name of a document that has been associated with an executable program.

windowstyle

Number 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.


The windowstyle named argument has these values:

Constant

Value

Description

vbHide

0

Window is hidden and focus is passed to the hidden window.

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 identification (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.

Note The Shell function runs other programs asynchronously. This means you can’t depend on a program started with Shell to be finished executing before the statements following the Shell function in your application are executed.

See Also

AppActivate Statement.

Example

This example uses the Shell function to run an application specified by the user.


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