Shell Function

Runs an executable program and returns a Variant (Boolean) if successful, representing the result.

Syntax

Shell([pathname[,windowstyle]])

The Shell function syntax has these named arguments:

Part Description
pathname

Optional; Variant (String). Name of the program to execute and any required arguments or command-line switches; may include directory or folder and drive.

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.

The windowstyle named argument has these values:

Constant Value Description
cdbHide 0 Window is hidden and focus is passed to the hidden window.
cdbNormalFocus 1 Window has focus and is restored to its original size and position.
cdbMinimizedFocus 2 Window is displayed as an icon with focus.
cdbMaximizedFocus 3 Window is maximized with focus.
cdbNormalNoFocus 4 Window is restored to its most recent size and position. The currently active window remains active.
cdbMinimizedNoFocus 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 True. If the Shell function can't start the named program, it returns False.

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

The windowstyle argument is only considered on Windows system.

Example

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

 

See Also

GetOpenFileName Function