Shell Function

Named Arguments

Yes

Syntax

Shell(pathname[,windowstyle])

pathname

Use: Required

Data Type: Variant (String)

Name of the program to execute.

windowstyle

Use: Optional

Data Type: Variant (Integer)

The style of window and whether it receives the focus.

Return Value

A Variant of subtype Double.

Description

Launches another application and, if successful, returns that application's task ID.

Rules at a Glance

  • pathname can include a drive letter. If a drive letter isn't included in pathname, the current drive is assumed. If a drive letter is used, the fully qualified path is required unless the file is located in the current directory.

  • pathname can include a folder name. If the folder name isn't included in pathname, the current folder is assumed.

  • pathnamecan include any command-line arguments and switches required by the application.

  • Visual Basic includes the following intrinsic constants for setting the windowstyle argument:

vbHide

Value: 0

New application window is: hidden

Focus: New Application

vbNormalFocus

Value: 1

New application window is: shown in its original position and size

Focus: New Application

vbMinimizedFocus

Value: 2

New application window is: displayed as an icon

Focus: New Application

vbMaximizedFocus

Value: 3

New application window is: maximized

Focus: New Application

vbNormalNoFocus

Value: 4

New application window is: shown in its original position and size

Focus: Current Application

vbMinimizedNoFocus

Value: 6

New application window is: displayed ...

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.