You can run another application by using the Shell statement.
'// this code calls c: est.exe
Shell "c:\test.exe", vbNormalFocus
You can also call any program in the windows directory, such as regsvr32, notepad, and explorer
So,
Shell "notepad", vbNormalFocus
Runs notepad, and
Shell "explorer", vbNormalFocus
runs explorer. You can also pass any command parameters you need. For example:
Shell "notepad C:\test.txt", vbNormalFocus
runs notepad, and tells it to open C:\test.txt. Note that if the path you pass contains spaces, you need to surround it by quotes:
Shell "notepad ""C:\dir with spaces\test.txt""", vbNormalFocus
which is actually the equivalent of passing this:
notepad "
C:\dir
with spaces\test.txt"
The second parameter specifies the startup position, and can be one of the following:
Constant | Value | Description |
vbHide | 0 | Window is hidden and focus is passed to the hidden window. |
vbNormalFocus | 1 | Window has focus and is restored to its original size and position. |
vbMinimizedFocus | 2 | Window is displayed as an icon with focus. |
vbMaximizedFocus | 3 | Window is maximized with focus. |
vbNormalNoFocus | 4 | Window is restored to its most recent size and position. The currently active window remains active. |
vbMinimizedNoFocus | 6 | Window is displayed as an icon. The currently active window remains active. |
The shell function also returns a TaskID (double), that you can use with the AppActivate statement:
Private dblNotePadID As Double
'// runs word
Private Sub cmdRunNotePad_Click()
dblNotePadID = Shell("notepad", vbNormalFocus")
End Sub
'// activates word at a later stage
Private Sub cmdActivateNotePad_Click()
AppActivate dblNotePadID
End Sub
Comments