Using the VBA Shell function

The VBA Shell function makes launching another program relatively easy. The following example starts the Windows Calculator program, which is named CALC.EXE:

On Error Resume Next AppActivate "Calculator" If Err <> 0 Then Err = 0

TaskID = Shell(Program, 1)

If Err <> 0 Then MsgBox "Can't start " & Program End If End Sub

This modified procedure uses an AppActivate statement to activate the application (Windows Calculator in this case) if it's already running. The argument for AppActivate is the Caption of the application's title bar. If the AppActivate statement generates an error, it means the Calculator isn't running. If it's not running, the routine starts the application using the Shell function.

0 0

Post a comment