Open Any Third Party Application Using Shell Function

How to open any third party application using the shell function in Excel VBA. We can open applications like Acrobat Reader, Google browser, OpenOffice, CamtasiaStudio, etc. automatically using the Shell function. ‘It runs an executable program and returns a¬†Variant¬†(Double) representing the program’s task ID if successful; otherwise, it returns zero.’

Syntax of Shell Function: Shell(pathname, [ windowstyle ])

PathnameThis named argument is required; the data type is Variant (String). We specify the path to the ‘exe’ file of the application or program
windowstyleThis name argument is optional. The data type is a 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.
Named Arguments of Shell Function

The windowstyle named argument can have these values:

vbHide0Window is hidden and focus is passed to the hidden window.
vbNormalFocus1Window has focus and is restored to its original size and position.
vbMinimizedFocus2Window is displayed as an icon in the taskbar with focus.
vbMaximizedFocus3Window is maximized with focus.
vbNormalNoFocus4Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus6Window is displayed as an icon. The currently active window remains active.
Windowstyle Named Argument

Open Any Third Party Application Using Shell Function in VBA

If the Shell function executes the named file successfully, 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, and vbMinimizeFocus all place the application in the background.

Reference: Shell function