SHELL |
| SHELL(pathname [,windowstyle]) |
Returns the program's task id from running an executable programs (Double). |
| pathname | The full path of the program to execute (String). |
| windowstyle | (Optional) The constant specifying the style of the window (Integer): 0 = vbHide 1 = vbNormalFocus 2 = vbMinimizedFocus 3 = vbMaximizedFocus 4 = vbNormalNoFocus 5 = vbMinimizedNoFocus |
| REMARKS |
| * The taskID is a unique number that identifies the running program. * If "windowstyle" is left blank, then 2 is used. * By default this function runs other programs asynchronously. * Specifying a windowstyle of 1 opens the application in normal size and gives it focus. * You can use progID "WScript.Shell" with CREATEOBJECT to create a windows script host shell object. * When using "WScript.Shell" you can wait for completion, read environment variables and even read and write from the registry. * When using "WScript.Shell" you can even indicate when the process finishes. * The equivalent .NET function is Microsoft.VisualBasic.Interaction.Shell * For the Microsoft documentation refer to learn.microsoft.com |
Dim dbAppID As Double
dbAppID = Shell("Microsoft Word", 1)
dbAppID = Shell("C:\Windows\Calc.exe", 1)
dbAppID = Shell("Notepad.exe", vbMaximizedFocus)
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
oShell.Run "notepad.exe"
Debug.Print oShell.ExpandEnvironmentStrings("%USERNAME%")
Dim sPath As String
sPath = "HKEY_CURRENT_USER\software\microsoft\office\16.0\excel\options\open1"
Debug.Print oShell.RegRead(sPath)
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top