Activating Another Application

 < Day Day Up > 



You might be wondering what steps to take if the application you want to use is already open. Using the Shell function would create a second instance of the program taking up valuable memory. In most cases, you should activate the program that's running, rather than creating a new instance of the program.

Consider the following example, in which the ActivateCalculator procedure uses the AppActivate statement to activate the application if the application is already running. The argument for the AppActivate statement is the caption of the application's title bar. If the AppActivate statement generates an error, it means the Calculator isn't running, so the procedure will start the application.

Sub ActivateCalculator()
AppFile = "Calc.exe"
On Error Resume Next
AppActivate "Calculator"
If Err <> 0 Then
CalcTaskID = Shell(AppFile, vbNormalFocus)
If Err = 0 Then MsgBox "Unable to start the Calculator"
End If
End Sub



 < Day Day Up > 



Microsoft Excel 2003 Programming Inside Out
Microsoft Office Excel 2003 Programming Inside Out (Inside Out (Microsoft))
ISBN: 0735619859
EAN: 2147483647
Year: 2006
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net