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.
Shell(pathname [, windowstyle ] )
The Shell function syntax has these arguments (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.):
The windowstyle named argument has these values:
||Window is hidden and focus is passed to the hidden window. The vbHide constant is not applicable on Macintosh platforms.
||Window has focus and is restored to its original size and position.
||Window is displayed as an icon with focus.
||Window is maximized with focus.
||Window is restored to its most recent size and position. The currently active window remains active.
||Window is displayed as an icon. The currently active window remains active.
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.
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.
' Run Calculator.
RetVal = "C:\WINDOWS\CALC.EXE" 1