AppActivate Statement

See Also1P8A1SN              Example8LSN0LN>Low

Activates an application window.

Syntax

AppActivate titletext

Remarks

The argument titletext is a string expression1330R89 that is the name that appears in the title bar of the application window to activate.  If there is more than one instance of the application, the operating environment arbitrarily selects the one to activate.  The name that appears in the title bar and titletext must match character-for-character, but the comparison is not case sensitive:  "Calculator" and "calculator" appear identical.

The AppActivate statement changes the focus to the named application window but does not affect whether it is maximized or minimized.  Focus moves from the activated application window when the user takes some action to change the focus or close the window.


See Also

Shell Function3DWKG4E

SendKeys Statement41LDB48


AppActivate Statement Example

The example uses the AppActivate statement to change focus between Visual Basic and the Microsoft Windows Calculator application.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim   I, Msg, X                       ' Declare variables.

   AppActivate "Microsoft Visual Basic"  ' Change focus to Visual Basic.

   SendKeys "%{  }{ Down 3}{ Enter}", True  ' Minimize Visual Basic

   X = Shell("Calc.exe", 1)              ' Shell the Calculator.

   For I = 1 To 100                      ' Set up counting loop.

      SendKeys I & "{ +}", True           ' Send keystrokes to Calculator

   Next I                                '  to add each value of I.

   SendKeys "=", True                    ' Get grand total.

   AppActivate "Microsoft Visual Basic"  ' Focus back to Visual Basic.

   Msg = "Choose OK to close Calculator."      ' Stop to see results.

   MsgBox Msg

   AppActivate "Calculator"              ' Focus back to Calculator.

   SendKeys "%{ F4}", True                ' Alt+F4 to close Calculator.

   AppActivate "Microsoft Visual Basic"  ' Change focus back to Visual Basic.

   SendKeys "%{  }{ Enter}", True          ' Restore Visual Basic to size.

End Sub