Shell

Syntax

Shell Application$ [WindowStyle]

Remarks

Starts another application (such as Microsoft Excel) or process (such as an MS-DOS batch file or executable file). In Windows, if the specified application is already running, Shell starts another instance of the same application; on the Macintosh, Shell activates the instance that is already running.

Note

In Word version 6.0 for Windows NT and Word version 7.0, you cannot depend on a program started with Shell to be finished loading before the instructions following the Shell statement in your macro are run. Any instructions that try to communicate with an application that has not finished loading will generate errors or unexpected results. To avoid this problem, you can use a For...Next loop to delay the instructions until the other application is loaded. For an example, see DDEInitiate.

Argument

Explanation

Application$

In Windows, the path and filename required to find the application, as well as any valid switches or arguments you choose to include, just as you would type them in the Run dialog box. To display a command window, specify Environ$("COMSPEC") (Windows 3.x), Environ$("COMMAND") (Windows 95), or Environ$("CMD") (Windows NT) as Application$.

On the Macintosh, Application$ is the application name or the signature returned by the MacID$() function. It is generally preferable to use the signature instead of the application name (for example, MacID$("XCEL") instead of "Microsoft Excel") because, unlike the application name, the signature never changes.

Application$ can be a document filename by itself, provided the file is associated with an application. (In Windows, a filename is associated with an application if its extension is registered in the [Extensions] section of the WIN.INI file (or the registry in Windows 95 and Windows NT). On the Macintosh, associations between filenames and applications are created automatically; you can use SetFileCreatorAndType to change an association.) Shell starts the associated application and opens the document.


Argument

Explanation

WindowStyle

In Windows, how the window containing the application should be displayed (some applications ignore this):

0 (zero) Minimized window (icon)

1 Normal window (current window size, or previous size if minimized)

2 Minimized window (for Microsoft Excel compatibility)

3 Maximized window

4 Deactivated window

On the Macintosh, WindowStyle 0 (zero), 1, 2, and 3 are effectively the same: The application window (which has only one size) is activated. Set WindowStyle to 4 to start an application but leave Word active.


Examples

This Windows example starts Notepad and loads the document TORT.TXT:


Shell "Notepad TORT.TXT"

The following Macintosh example starts Microsoft Excel but leaves Word active:


Shell MacID$("XCEL"), 4

The following Windows example creates a text-only file (DOCLIST.TXT) that lists documents with the filename extension .DOC in the C:\WINWORD folder. You might use an instruction like this to create a file you can open later for sequential input. The "/c" switch ensures that control is returned to Word after the command line following "/c" is run.


Shell Environ$("COMSPEC") + " /c dir /b C:\WINWORD\*.DOC > DOCLIST.TXT"

See Also

AppActivate, DDEInitiate(), Environ$(), MacID$(), SetFileCreatorAndType