Function Windows API Class

ShellNoWait

Executes a Windows or DOS program without waiting for it to complete. Its window gets the specified focus. Function optionally sends keystrokes to the program. Function returns either 0 (zero) upon success or the number of the error encountered.

Signature (Visual Basic / VBA)

Public Function ShellNoWait( _
      ByVal vCommand As String _
    , Optional ByVal vFocus As Variant _
    , Optional ByVal vSendKeys As Variant _
    ) As Long

Code Example

    ShellNoWait("CharMap.Exe", vbNormalNoFocus) = 0
    ShellNoWait("NotePad.Exe NewFile.Txt") = 0

Parameters

Parameter Description
vCommand The Windows or DOS command that is to be executed. This command line must include a program name, and it can optionally include one or more command line arguments.
vFocus The focus given to program's window. Should be one of the Visual Basic focus Constants like vbNormalFocus, vbNormalNoFocus, etc. vFocus defaults to vbNormalFocus if it is missing or Null or cannot be fixed-up to a number.
vSendKeys String that will be sent to the program as keystrokes after it is started. vSendKeys defaults to an empty string (no keystrokes will be sent) if it is missing or Null or cannot be fixed-up to a string.

Notes & Version History

Warning vSendKeys is ignored if vFocus is vbHide, vbMinimizedNoFocus, or vbNormalNoFocus.